AlphaComposite.CLEAR不工作 [英] AlphaComposite.CLEAR not working

查看:222
本文介绍了AlphaComposite.CLEAR不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JLayeredPane的2 JPanels。其中一个显示PDF和重叠的人有一个透明的背景(我已经使用setOpaque(假))。
现在,我可以添加图纸透明面板,这样看来我确实注释的PDF格式。我想有一个橡皮擦工具擦除这些注解。我试着用下面的code

I have two JPanels on a JLayeredpane. One of them displays a pdf and the overlapping one has a transparent background (I have used setOpaque(false)). Now I can add drawings to the transparent panel such that it seems I'm actually annotating the pdf. I want to have a eraser tool to erase these annotations. I tried using the following code

@Override
public void draw(Graphics2D g2) {
    g2.setPaint(Color.WHITE);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
    g2.setBackground(new Color(255, 255, 255, 0));
    g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    g2.draw(path);
}

其中路径是从多条线路构成的形状。现在不是绘制的透明的行在早期的图画黑线正在制定。我在哪里去了?

where path is the shape constituted from a number of lines. Now instead of drawing a transparent line over the earlier drawings a black line is being drawn. Where am I going wrong?

推荐答案

注意 AlphaComposite.CLEAR 的一个实例,相当于 AlphaComposite.Clear ,就是清除这两个颜色和目的地的字母的组合模式。 无论源也不目的地被用作输入。实际上,你不能的的有清除。这例如说明了一个常见的​​用法。为了得到你想要的效果,保持不变图像的副本和画()在目的地的橡皮擦大小的子图像的BufferedImage 作为鼠标的移动。

Note that an instance of AlphaComposite.CLEAR, equivalent to AlphaComposite.Clear, is a composite mode that clears both the color and the alpha of the destination. "Neither the source nor the destination is used as input." In effect, you can't draw with CLEAR. This example illustrates a common usage. To get the effect you want, keep a copy of the unaltered image and draw() an eraser-sized sub-image over the destination BufferedImage as the mouse moves.

这篇关于AlphaComposite.CLEAR不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆