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

最新文章

  1. 面试复习(C++)之直接选择排序
  2. 条件变量pthread_cond_t怎么用
  3. twitter storm源码走读之2 -- tuple消息发送场景分析
  4. Java创建WebService服务及客户端实现
  5. curl 取不到第二个参数解决方法
  6. NENU_CS_segment_tree
  7. jquery查找父元素、子元素(个人经验总结)
  8. linux定时执行php脚本
  9. java替换字符串和用indexof查找字符
  10. C++中使用class和structkeyword的不同
  11. Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序
  12. Redmine管理项目1-自定义属性
  13. JAVAEE学习路线分享
  14. jaeger 使用初探
  15. 通过 phpmyadmin getshell
  16. windows -休眠
  17. tomcat localhost
  18. vue_resource和axios
  19. 微信小程序《沈航二手书》
  20. Hive四种数据导入方式介绍

热门文章

  1. [转]Win7独立语言包下载
  2. 帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数
  3. svnserve配置文件详析
  4. oracle日期合并 分别用逗号或者分号隔开
  5. ny10 skilng
  6. FreeRTOS基础篇教程目录汇总
  7. python学习笔记(16)--django的安装
  8. iOS导航栏背景,标题和返回按钮文字颜色
  9. java中常用的类,包,接口
  10. 传智播客《巴巴运动网视频教程(11-106)》avi格式以及兴许44集视频包括所有源码和资源