【发布时间】:2016-06-09 16:52:43
【问题描述】:
我正在将 .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);
【问题讨论】: