【发布时间】:2023-03-28 02:15:02
【问题描述】:
给定一个图像文件,比如 PNG 格式,我如何获得一个 int [r,g,b,a] 数组,表示位于第 i 行第 j 列的像素?
到目前为止,我从这里开始:
private static int[][][] getPixels(BufferedImage image) {
final byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
final int width = image.getWidth();
final int height = image.getHeight();
int[][][] result = new int[height][width][4];
// SOLUTION GOES HERE....
}
提前致谢!
【问题讨论】:
-
从图像中获取像素数据作为
int,将其传递给Color(int, boolean) -
您能否提供代码作为接受的答案?
-
“从图像中以 int 形式获取像素数据,将其传递给 Color(int, boolean)”:这是一堆废话
-
@gpasch 我认为您需要重新表述该评论,以使其礼貌和建设性的部分更加明显。否则它只会读作“近五年前提到的东西不再是最现代的解决方案”,并且可能被误认为是完全没有信息的东西,甚至可能是粗鲁的。
标签: java arrays pixel bufferedimage rgba