本文转自:http://www.infosys.tuwien.ac.at/teaching/courses/WebEngineering/References/java/docs/api/java/awt/image/PixelGrabber.html

PixelGrabber 类实现可以附加在 Image 或 ImageProducer 对象上获得图像像素子集的 ImageConsumer。下面是一个示例:

 public void handlesinglepixel(int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
// Deal with the pixel as necessary...
} public void handlepixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
handlesinglepixel(x+i, y+j, pixels[j * w + i]);
}
}
}

  

PixelGrabber

public PixelGrabber(Image img,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)
创建一个 PixelGrabber 对象,以从指定图像将像素矩形部分 (x, y, w, h) 抓取到给定的数组中。以默认的 RGB ColorModel 形式将像素存储到数组中。像素 (i, j)((i, j) 处于矩形 (x, y, w, h) 内)的 RGB 数据存储在数组中的 pix[(j - y) * scansize + (i - x) + off] 位置处。

参数:
img - 从中检索像素的图像
x - 从图像中进行检索的像素矩形左上角 x 坐标,其相对于默认(未缩放)图像大小
y - 从图像中进行检索的像素矩形左上角 y 坐标
w - 要检索的像素矩形的宽度
h - 要检索的像素矩形的高度
pix - 用于保存从图像中检索的 RGB 像素的整数数组
off - 数组中存储第一个像素的偏移量
scansize - 数组中一行像素到下一行像素之间的距离
另请参见:
ColorModel.getRGBdefault()

PixelGrabber

public PixelGrabber(ImageProducer ip,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)
创建一个 PixelGrabber 对象,以从指定 ImageProducer 所生成的图像中将像素矩形部分 (x, y, w, h) 抓取到给定的数组中。以默认的 RGB ColorModel 形式将像素存储到数组中。像素 (i, j)((i, j) 处于矩形 (x, y, w, h) 内)的 RGB 数据存储在数组中的 pix[(j - y) * scansize + (i - x) + off] 位置处。

参数:
ip - 生成图像的 ImageProducer,从该图像中检索像素
x - 从图像中进行检索的像素矩形左上角 x 坐标,其相对于默认(未缩放)图像大小
y - 从图像中进行检索的像素矩形左上角 y 坐标
w - 要检索的像素矩形的宽度
h - 要检索的像素矩形的高度
pix - 用于保存从图像中检索的 RGB 像素的整数数组
off - 数组中存储第一个像素的偏移量
scansize - 数组中一行像素到下一行像素之间的距离
另请参见:
ColorModel.getRGBdefault()

PixelGrabber

public PixelGrabber(Image img,
int x,
int y,
int w,
int h,
boolean forceRGB)
创建一个 PixelGrabber 对象,以从指定的图像中抓取像素矩形部分 (x, y, w, h)。如果每次调用 setPixels 都使用相同的 ColorModel,则像素以原 ColorModel 形式存储,否则像素将以默认 RGB ColorModel 形式存储。如果 forceRGB 参数为 true,则像素将总是以默认 RGB ColorModel 形式存储。无论是哪种情况,PixelGrabber 都会分配一个缓冲区来保存这些像素。如果 (w < 0) 或 (h < 0),则它们默认为传递信息时保存的源数据的宽度和高度。

参数:
img - 要从中检索图像数据的图像
x - 从图像中进行检索的像素矩形左上角 x 坐标,其相对于默认(未缩放)图像大小
y - 从图像中进行检索的像素矩形左上角 y 坐标
w - 要检索的像素矩形的宽度
h - 要检索的像素矩形的高度
forceRGB - 如果总是应该将像素转换为默认 RGB ColorModel,则为 true

grabPixels

public boolean grabPixels()
throws InterruptedException
请求 Image 或 ImageProducer 开始传递像素,并等待传递完相关矩形中的所有像素。

返回:
如果成功抓取了像素,则返回 true;在中止、有错误或超时的情况下返回 false
抛出:
InterruptedException - 另一个线程中断了此线程。

最新文章

  1. python教程与资料
  2. Linux基本权限学习
  3. SoapUI 使用笔记
  4. BestCoder Round #72 (div.2)
  5. 学习bootstrap心得
  6. linux下samba环境搭建
  7. Wordpress-数据库结构分析(转)
  8. Linux操作系统上用数据泵导库
  9. Python、C和Java对比
  10. div+css实现未知宽高元素垂直水平居中
  11. Oracle EBS-SQL (MRP-1):检查期间内计划完成的任务.sql
  12. js的严格模式
  13. 防盗链与token运用
  14. 剑指Offer-对称的二叉树
  15. C++框架_之Qt的开始部分_概述_安装_创建项目_快捷键等一系列注意细节
  16. Saslauthd服务实现SMTP发信认证
  17. es6 实现数组的操作
  18. mycat 主从切换分析过程
  19. 前端Vue之vue的基本操作
  20. 15 图-图的遍历-基于邻接矩阵实现的BFS与DFS算法

热门文章

  1. 第一章 Web MVC简介
  2. UML 小结(5)- 图解 Rational Rose 的详细安装过程
  3. MySQL中的配置参数interactive_timeout和wait_timeout(可能导致过多sleep进程的两个参数)
  4. android 播放语音文件出现 prepare failed ,不能下载amr文件
  5. EXT经验--在调试中通过查看handler的第一个参数的xtype得知该参数信息及该handler的归属
  6. Scrum敏捷开发简介
  7. spring @resource @ Autowired
  8. 【C++基础】构造函数
  9. java001-Helloworld
  10. java基础知识回顾之javaIO类--内存操作流ByteArrayInputStream和ByteArrayOutputSteam(操作字节数组)