I am using org.imgscalr.Scalr(http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#solve) libraries to resize the images but the PNG with transparent background turns black when resized. My code is as mentioned below:
public void scaleImage(String originalImage, int width, int height) throws IOException {
File imgFl = new File(originalImage);
BufferedImage originalBufImage = ImageIO.read(imgFl);
BufferedImage scaledImage = Scalr.resize(originalBufImage, Scalr.Method.ULTRA_QUALITY, width, height, Scalr.OP_BRIGHTER);
File outputfile = new File(originalImage);
String fileExtension = originalImage.substring(originalImage.indexOf(".") + 1, originalImage.length());
ImageIO.write(scaledImage, fileExtension, outputfile);
}
Does anyone has any clue about this?
Thanks, Abhishek
I don't know why it happens, but assuming that nothing else is black in the image, you can make the black color transparent with this method:
It returns an image with all RGB values that match the color as transparent.
I hope this helped.