2
我正在读取.jpg文件作为整数数组(源)并试图从相同数据生成新图像,但代码正在生成黑色图像。但它应该产生重复的图像作为源。无法从源输入生成相同的输出图像
String srcName = "input.jpg";
File srcFile = new File(srcName);
BufferedImage image = ImageIO.read(srcFile);
System.out.println("Source image: " + srcName);
int w = image.getWidth();
int h = image.getHeight();
int[] src = image.getRGB(0, 0, w, h, null, 0, w);
System.out.println("Array size is " + src.length);
BufferedImage dstImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// generating destination image with same source array
dstImage.setRGB(0, 0, w, h, src, 0, w);
String dstName = "output.jpg";
File dstFile = new File(dstName);
ImageIO.write(dstImage, "jpg", dstFile);
System.out.println("Output image: " + dstName);
似乎是正确的修复。 – PyThon
不客气。快乐编码:) – lupz