這顯然是一個知道的錯誤,我看到了幾個建議(this是一個),建議使用Toolkit#createImage
來代替,這顯然忽略了顏色模型。
我測試了這個,它似乎工作正常。
public class TestImageIO01 {
public static void main(String[] args) {
try {
Image in = Toolkit.getDefaultToolkit().createImage("C:\\hold\\test\\13652375852388.jpg");
JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(in)), "Yeah", JOptionPane.INFORMATION_MESSAGE);
BufferedImage out = new BufferedImage(in.getWidth(null), in.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = out.createGraphics();
g2d.drawImage(in, 0, 0, null);
g2d.dispose();
ImageIO.write(out, "jpg", new File("C:\\hold\\test\\Test01.jpg"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
nb-我用JOptionPane
來驗證傳入的圖像。當使用ImageIO
它帶有紅色色調,Toolkit
它看起來很好。
更新
而一個explantation
EMM,你選擇一個漂亮的照片我喜歡你的味道:) 我不知道什麼是顏色的問題,但嘗試這個 'BufferedImage的IMG = ImageIO.read(new File(「path/to/image」));' – Azad 2013-04-09 06:55:26
其實,我試過了,但是失敗了...... – victorunique 2013-04-09 07:04:31
[用紅色面具創建的java緩衝圖像](http:// stackoverflow.com/questions/12963685/java-buffered-image-created-with-red-mask) – haraldK 2016-05-19 09:27:34