However, Java docs did a minimal explanation what these image types are used for and how would it affect the BufferedImage to be created. You can click to vote up the examples that are useful to you. 12 Java BufferedImage class has a long list of class variables known as the image type which can be used as an argument for the BufferedImage constructor. Returns true if the specified image is a grayscale image whatever is the image type (GRAY, RGB, ARGB.) static, load(java.io.
IMAGETYPE BUFFEREDIMAGE JAVA CODE
JPEG does not support alpha, so if your image has alpha then ImageIO cannot write it to JPEG. In the code, the line which the error is on, is in the constructor and looks like this: // Get the pixel array from the BufferedImage this.pixels ( (DataBufferInt) image.getRaster ().getDataBuffer ()).getData () As I understand this, the BufferedImage isn't of the type BufferedImage.TYPEINTRGB or BufferedImage.TYPEINTARGB. The following code examples are extracted from open source projects. 105 Java 25 8K Embedded Technologies 22.1K Java APIs 138.1K Java Development Tools 165.3K Java EE (Java Enterprise Edition) 17 Java Essentials 157 Java 8 Questions 85.9K Java Programming 79 Java Puzzle Ball 65.1K New To Java 1.7K Training / Learning / Certification 13.8K Java HotSpot Virtual Machine 94.2K Java SE 13. I had the same issue in OpenJDK 7 and I managed to get around this exception by using an imageType of TYPE_3BYTE_BGR instead of TYPE_4BYTE_ABGR using the same OpenJDK.Ģ019 answer: Make sure your BufferedImage does not have alpha transparency. If you import the image back to Java, the transparency is still there, though. 2019 answer: Make sure your BufferedImage does not have alpha transparency.
I had the same issue in OpenJDK 7 and I managed to get around this exception by using an imageType of TYPE3BYTEBGR instead of TYPE4BYTEABGR using the same OpenJDK. Most viewers, when opening, assume the four channels must correspond to a CMYK (not ARGB) and thus the red tint. If you import the image back to Java, the transparency is still there, though. OpenJDK does not have a native JPEG encoder, try using Sun's JDK, or using a library (such as JAIĪFAIK, regarding the "pinkish tint", Java saves the JPEG as ARGB (still with transparency information).