我無法讀取圖像創建。如果我做了以下java的緩衝圖像與紅色面具
URL url = new URL("http://tctechcrunch2011.files.wordpress.com/2012/10/gmm.jpg");
ImageInputStream stream = ImageIO.createImageInputStream(url.openStream());
ImageReader reader = ImageIO.getImageReaders(stream).next();
reader.setInput(stream, true, true);
BufferedImage image = reader.read(0);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageWriter writer = ImageIO.getImageWritersByFormatName("JPEG").next();
ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
writer.setOutput(ios);
IIOImage ioImage = new IIOImage(image, null, null);
writer.write(ioImage);
ios.close();
FileOutputStream fos = new FileOutputStream("badimage.jpeg");
fos.write(bos.toByteArray());
fos.close();
圖像寫入一個紅色的色調。是否有一些選項需要設置爲正確讀取此圖像?
看一看[Java中奇數彩色JPEG圖片與ImageIO的(http://blog.idrsolutions.com/2009/04 /奇數有色JPEG文件功能於Java的與-的ImageIO /)。我聽說過幾次,但從未遇到過這個問題,我使用PNG – MadProgrammer