Image transformation results in a red image?

孤者浪人 提交于 2019-12-01 05:51:04

Having an image develop a tint usually means the image is being rendered using the wrong colorspace, Adobe RGB vs. sRGB being a perennial favorite. Try changing TYPE_INT_ARGB to TYPE_INT_RGB in your code.

You can also try the following type: BufferedImage.TYPE_3BYTE_BGR

If you have any images already converted and those are almost pinkish/reddish.

You can convert those into RGB again.

try {
        File folder = new File("photo/old");
        File[] list = folder.listFiles();
        for (File f : list) {
            String url = f.getAbsolutePath();
            String replce1 = url.replace('\\', '/');
            File file = new File(replce1);
            if (file.exists()) {
                FileInputStream fis = new FileInputStream(file);

                byte[] buff = new byte[fis.available()];
                fis.read(buff);

                BufferedImage bi = ImageIO.read(file); 
                BufferedImage biOriginal = new BufferedImage(1200, 800,
                    BufferedImage.TYPE_INT_RGB);
                Graphics2D g = resizedImage.createGraphics();
                g.drawImage(bi, 0, 0, 1200, 800, null);
                g.dispose();

                fis.close();

                FileOutputStream fos2 = new FileOutputStream("photo/new/"+file.getName());
                ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                ImageIO.write(biOriginal, Main.extensionWithotDot, baos2);
                baos2.flush();
                byte[] imageInByte2 = baos2.toByteArray();
                fos2.write(imageInByte2);
                fos2.close();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!