Java缓冲图像RescaleOp透明度问题

Java缓冲图像RescaleOp透明度问题

本文介绍了Java缓冲图像RescaleOp透明度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  BufferedImage buff = new我有一个问题,我创建了一个像这样具有透明像素的BufferedImage: BufferedImage(i.getWidth(null),i.getHeight(null),BufferedImage.TYPE_INT_ARGB); 

并且它可以正常工作,直到我通过RescaleOp将其过滤为黑色。当我这样做时,图像消失。这是我的完整代码,所以你可以看到我如何设置它:

  BufferedImage buff = new BufferedImage(i.getWidth (null),i.getHeight(null),BufferedImage.TYPE_INT_ARGB); 
Graphics2D g = buff.createGraphics();
g.drawImage(i,0,0,null);
g.dispose();
RescaleOp filter = new RescaleOp(lightlevel,0f,null);
buff = filter.filter(buff,null);

我的问题是,我该如何解决这个问题,以便缓冲图像的像素变暗而不影响透明度?

解决方案

您可以尝试处理 alpha ,如图 ,并为所有颜色组件使用相同的 lightLevel


I seem to be having an issue where I create a BufferedImage which has transparent pixels like this:

BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);

and it works fine until I filter it through the RescaleOp to darken it. When I do this, the image disappears. Here is my complete code just so you can see how I am setting this up:

    BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = buff.createGraphics();
    g.drawImage(i, 0, 0, null);
    g.dispose();
    RescaleOp filter = new RescaleOp(lightlevel, 0f, null);
    buff = filter.filter(buff, null);

My question is, how do I fix this so the buffered image will have its pixels darkened without affecting the transparency?

解决方案

You could try the RescaleOp that handles alpha, illustrated here, and use the same lightLevel for all color components.

这篇关于Java缓冲图像RescaleOp透明度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:16