我必须处理非常大的(1-2 2GB) Tiff文件,并且只需要在像素上做一些RGB操作,其中我只进行局部校正(修改后的像素的颜色只取决于它的旧值,而不是例如相邻像素)。它们(JAVA)是否可以将文件作为某种像素流读取,对RGB值进行调整,然后立即将内容写入另一个文件?我将没有足够的内存将整个文件存储在RAM中(或者至少我希望我可以避免这种情况)
谢谢任何提示..。
THX
-Marco
发布于 2020-07-25 05:22:59
我会这样做:
public BufferedImage correctRGB()
{
BufferedImage b = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//width and height are the width and height of the original image
Graphics g = b.getGraphics();
for(int x = 0; x < b.getHeight(); x++)
{
for(int y = 0; y < b.getWidth(); y++)
{
//loop through all the pixels in the image ONCE to spare RAM
int pixels = b.getRGB(x, y);
int alpha = (pixels >> 24) &0xff;
int red = (pixels >> 16) &0xff;
int green = (pixels >> 8) &0xff;
int blue = pixels &0xff;
//in here you play around with the values
g.setColor(new Color(red, green, blue, alpha));
g.fillRect(x, y, 1, 1);
}
}
g.dispose();
return b;
}你现在基本上可以用argb值做任何你想做的事情了。例如,您可以通过执行red = 255 - red等操作将整个图像转换为负片。或者通过执行以下操作将整个图像转换为灰度
int average = (red + green + blue) / 3;
g.setColor(new Color(average, average, average, alpha));https://stackoverflow.com/questions/21817099
复制相似问题