簡體   English   中英

具有透明PNG的BufferedImage

[英]BufferedImage with Transparent PNG

我正在使用以下代碼將具有透明背景的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);

我似乎無法將背景設置為透明,它必須具有顏色?

無論如何要有透明的背景?

使用TYPE_INT_ARGB代替TYPE_INT_RGB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM