e665. 在图像中过滤三元色
2024-08-24 14:15:53
This example demonstrates how to create a filter that can modify any of the RGB pixel values in an image.
// This filter removes all but the red values in an image
class GetRedFilter extends RGBImageFilter {
public GetRedFilter() {
// When this is set to true, the filter will work with images
// whose pixels are indices into a color table (IndexColorModel
).
// In such a case, the color values in the color table are filtered.
canFilterIndexColorModel = true;
} // This method is called for every pixel in the image
public int filterRGB(int x, int y, int rgb) {
if (x == -1) {
// The pixel value is from the image's color table rather than the image itself
}
// Return only the red component
return rgb & 0xffff0000;
}
}
Here's some code that uses the filter:
// Get image
Image image = new ImageIcon("image.gif").getImage(); // Create the filter
ImageFilter filter = new GetRedFilter();
FilteredImageSource filteredSrc = new FilteredImageSource(image.getSource(), filter); // Create the filtered image
image = Toolkit.getDefaultToolkit().createImage(filteredSrc);
Related Examples |
最新文章
- 面试复习(C++)之直接选择排序
- 条件变量pthread_cond_t怎么用
- twitter storm源码走读之2 -- tuple消息发送场景分析
- Java创建WebService服务及客户端实现
- curl 取不到第二个参数解决方法
- NENU_CS_segment_tree
- jquery查找父元素、子元素(个人经验总结)
- linux定时执行php脚本
- java替换字符串和用indexof查找字符
- C++中使用class和structkeyword的不同
- Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序
- Redmine管理项目1-自定义属性
- JAVAEE学习路线分享
- jaeger 使用初探
- 通过 phpmyadmin getshell
- windows -休眠
- tomcat localhost
- vue_resource和axios
- 微信小程序《沈航二手书》
- Hive四种数据导入方式介绍