【发布时间】:2015-06-04 06:30:59
【问题描述】:
PixelGrabber在java中将像素放入数组中的顺序是什么?它是否首先沿图像宽度获取像素?还是先沿着图片的高度?
public static int[] convertImgToPixels(Image img, int width, int height) {
int[] pixel = new int[width * height];
PixelGrabber pixels = new PixelGrabber(img, 0, 0, width, height, pixel, 0, width);
try {
pixels.grabPixels();
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted Waiting for Pixels");
}
if ((pixels.getStatus() & ImageObserver.ABORT) != 0) {
throw new IllegalStateException("Image Fetch Aborted");
}
return pixel;
}
【问题讨论】:
-
这是我目前得到的代码: public static int[] convertImgToPixels(Image img, int width, int height) { int[] pixel = new int[width * height]; PixelGrabber 像素 = new PixelGrabber(img, 0, 0, width, height, pixel, 0, width);尝试 {像素.grabPixels(); } catch (InterruptedException e) { throw new IllegalStateException("Interrupted Waiting for Pixels"); } if ((pixels.getStatus() & ImageObserver.ABORT) != 0) { throw new IllegalStateException("Image Fetch Aborted"); } 返回像素; }
-
我正在尝试将像素从图像中取出并放入数组中