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