Originally Posted by
Asido
Hello,
I have such method:
private ImageIcon createSelectionPattern(int x, int y) {
BufferedImage bi = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(x, y, Transparency.BITMASK);
Graphics2D g2 = bi.createGraphics();
g2.setPaint(getFill());
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int INS = x / 6;
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f));
g2.fillRoundRect(0, 0, x, y, INS, INS);
g2.dispose();
return new ImageIcon(bi);
}
The problem is with calling this method:
I want to make this picture with 20% transparency, but with 0.2f I get 100% transparency. If I set it >=0.50f, I get 0% transparency, if <0.50f - 100% transparency. Why is it so?
Hi,
setComposite() is used to blend the source color with the destination color.i.e., Source is the one on which u draw and destination is the one that u draw. i.e., Source is similar to drawing board and destination is similar to the picture that u draw over the board.
AlphaComposite.getInstance(AlphaComposite.SRC_OVER ,0.20f) will perform the following action: Multiply the alpha value of the source with 0.20f and this is the alpha value of ur final image.
So,check the alpha value of ur source!!
AlphaComposite.SRC_OVER will work on the following logic:
If ur source is opaque,then it replaces the destination whereas if ur source is transparent,then ur destination remains unchanged.
If u have doubts, u can visit this site:
Blending Colors with AlphaComposite (Java Foundation Classes)
Hope this helps