简体   繁体   English

具有透明PNG的BufferedImage

[英]BufferedImage with Transparent PNG

I'm uploading a PNG with a transparent background to a Java server using the below code 我正在使用以下代码将具有透明背景的PNG上传到Java服务器

        byte[] imageData = Base64.decodeBase64(encodedImage);

        ByteArrayInputStream bais = new ByteArrayInputStream(imageData);
        BufferedImage bufferedImage = ImageIO.read(bais);
        BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(),
                bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
        newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.OPAQUE, null);

        Scene scene = sceneService.getScene(sceneId);

        java.io.File file = new java.io.File(Constants.TEMP_DIR_PATH
                +  UUID.randomUUID().toString() +".png");

        ImageIO.write(newBufferedImage, "PNG", file);

I can't seem to set the background as transparent, it has to have a color? 我似乎无法将背景设置为透明,它必须具有颜色?

Anyway to have a transparent background? 无论如何要有透明的背景?

使用TYPE_INT_ARGB代替TYPE_INT_RGB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM