用 PixelGrabber,
public PixelGrabber(Image img,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)参数:
Image img,
x,y 左上角坐标, w, h: 要提取的图象宽度和高度, pixels:存放象素颜色值的数组, off: 数组偏移,0. scansize: 每行宽度,wpublic 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;
}
}取得象素值后, 用以下方法得到颜色分量.
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 PixelGrabber(Image img,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)参数:
Image img,
x,y 左上角坐标, w, h: 要提取的图象宽度和高度, pixels:存放象素颜色值的数组, off: 数组偏移,0. scansize: 每行宽度,wpublic 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;
}
}取得象素值后, 用以下方法得到颜色分量.
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...
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货