- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究将图像颜色排序为二维颜色数组(行/列)。我已经实现了 PixelGrabber,但我无法准确理解发生了什么,以及如何使用 data
对二维数组进行排序。谢谢!
File file = fc.getSelectedFile();
try {
BufferedImage img = ImageIO.read(file);
PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, false);
if (grabber.grabPixels()) {
int width = grabber.getWidth();
int height = grabber.getHeight();
int[][] imageColors = new int[width][height]; //I want to store colors in here
int[] data = (int[]) grabber.getPixels();
}
} catch (Exception f) {
}
最佳答案
基本上,从 PixelGrabber
返回的像素数组是像素数据的一维数组,它基本上是图像数据的“平面”表示
要获取给定 x/y 位置处的特定像素,您需要将数组中的位置偏移 (y * width) + x
。因此,要将像素数据从一维数组复制到二维数组,您需要一个复合 for 循环。例如...
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
imageColors[x][y] = data[(y * width) + x];
}
}
关于java - Swing PixelGrabber - 数据排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23899515/
我正在研究将图像颜色排序为二维颜色数组(行/列)。我已经实现了 PixelGrabber,但我无法准确理解发生了什么,以及如何使用 data 对二维数组进行排序。谢谢! File file = fc.
我正在编写一个程序,它将图像分为域和范围。在这个域中将是16X16矩阵。我正在使用 PixelGrabber 来获取像素。我已经使用 for 循环进行迭代,但它需要花费很多时间来处理。在 java 中
我试图实现 Hill Cipher通过抓取图像像素来对图像进行算法。事实证明,小图像加载得很好。 但是对于较大的图像(8MP或12MP),加载速度很慢;因此写入图像也很慢。 我使用 bufferedI
我想在 C# 中获取位图图像的所有像素值,并将其放入二维数组中。在 Java 中,使用 pixelgrabber 函数很容易做到。 C# 中 pixelgrabber (Java) 的等价函数是什么?
我需要加载图像,并获取图像在宽度和宽度上的像素值。我知道我需要使用 PixelGrabber 和 Image,但我不确定如何去做。我的代码到现在为止。 (假设所有必需的库都已导入,并且在 try 部分
我是一名优秀的程序员,十分优秀!