我得到了3 BufferedImages: A,C和D,它们都是带有颜色和alpha通道的图像。C必须是α-over D,但是对于A的透明层,其想法是:
我用new BufferedImage().createGraphics().drawImage(D).drawImage(C);做α混合。但是如何设置C的阿尔法呢?
我对使用BufferedImage的任何建议都持开放态度,但我更喜欢那些不对所有像素进行迭代并手动进行计算以提高性能的建议(希望如此)。
发布于 2017-01-20 00:22:55
对于具有统一alpha的图像,可以执行以下操作:
BufferedImage bim=null;
try {
bim=ImageIO.read(new File("..."));
}
catch (Exception ex) { System.err.println("error in bim "+ex); }
int wc=bim.getWidth(), hc=bim.getHeight();
BufferedImage b=new BufferedImage(wc, hc, BufferedImage.TYPE_INT_ARGB);
b.getGraphics().drawImage(bim, 0, 0, null);
BufferedImage b2=new BufferedImage(wc, hc, BufferedImage.TYPE_INT_ARGB);
RescaleOp no=new RescaleOp(new float[]{1f, 1, 1, 1f}, new float[]{0, 0, 0, -50}, null);
b2=no.filter(b, null);
BufferedImage b3=new BufferedImage(wc, hc, BufferedImage.TYPE_INT_ARGB);
b3.getGraphics().drawImage(bim, 0, 0, null);
float offset=(b2.getRGB(0, 0)&0xff000000)>>24, a=(b3.getRGB(0, 0)&0xff000000)>>24;
no=new RescaleOp(new float[]{1, 1, 1, 1}, new float[]{0, 0, 0, -a+offset}, null);
b3=no.filter(b3, null);现在b3有了b2的alpha。
对于带有非均匀阿尔法的图像,你必须在每个像素上工作。
https://stackoverflow.com/questions/41738990
复制相似问题