目标只是绘制一个位图,并在其顶部绘制消除位图底层区域的形状.
我创建了简单的概念证明代码,试图理解我应该如何去做.在这里的各种线程中,我发现了许多关于使用的提示:
android.graphics.PorterDuff.Mode.CLEAR
Run Code Online (Sandbox Code Playgroud)
下面的代码只是创建一个蓝色背景的屏幕,并添加自定义视图.此视图在其画布上绘制粉红色背景,位图图像(带有轻微边框以显示粉红色背景),黄色覆盖圆圈表示每个PorterDuffXfermode.
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff.Mode;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;
public class Test extends Activity {
Drawing d = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
RelativeLayout.LayoutParams rlp = null;
// Create the view for the xfermode test
d = new Drawing(this);
rlp = new RelativeLayout.LayoutParams(600, 900);
rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
d.setLayoutParams(rlp);
RelativeLayout rl = new RelativeLayout(this); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在OSX上创建一个带有Java的半透明窗口并添加一个JLabel.
这JLabel会每秒改变它的文字......

然而,该组件不能很好地重新粉刷.
我怎么解决这个问题?
如果可能的话,请粘贴修复源代码,这是我的:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import java.util.Timer;
import java.util.TimerTask;
public class Translucent {
public static void main( String [] args ) {
JFrame frame = new JFrame();
frame.setBackground( new Color( 0.0f,0.0f,0.0f,0.3f));
final JLabel label = new JLabel("Hola");
label.setFont( new Font( label.getFont().getFamily(), Font.PLAIN, 46 ) );
label.setForeground( Color.white );
frame.add( label );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );
Timer timer = new …Run Code Online (Sandbox Code Playgroud) 在我的问题中,我有一个不透明的JPanel和另一个半透明(半透明)的JPanel,它位于第一个JPanel上.当我在顶部JPanel上添加单选按钮时.问题是每当我在每个单选按钮的标签区域上输入鼠标时(每次我将鼠标从标签上移开),它会变得越来越暗.
package trial;
import java.awt.Color;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Test {
public static void main(String arg[]){
JFrame rootframe = new JFrame("Test panel");
rootframe.setSize(800, 550);
rootframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
JPanel basePanel = new JPanel(); //fills rootFrame
basePanel.setOpaque(true);
basePanel.setBackground(Color.yellow );
JPanel panelContainingRadioButtons = new JPanel();//wraps radio buttons
panelContainingRadioButtons.setOpaque(true);
panelContainingRadioButtons.setBackground(new Color(0,0,0,100) );
ButtonGroup buttonGroup1 = new ButtonGroup();
JRadioButton jRadioButton1 = new JRadioButton();
jRadioButton1.setText("Text A...............................");
jRadioButton1.setOpaque(false);
jRadioButton1.setForeground( Color.white);
buttonGroup1.add(jRadioButton1);
JRadioButton jRadioButton2 = new JRadioButton();
jRadioButton2.setOpaque(false);
jRadioButton2.setForeground( Color.white);
buttonGroup1.add(jRadioButton2);
jRadioButton2.setText("Text B.......................");
JRadioButton …Run Code Online (Sandbox Code Playgroud) 我有多个透明BufferedImage实例,我想将它们叠加在一起(也就是Photoshop图层)并烘焙成一个BufferedImage输出.我该怎么做呢?
第一次在这里发帖 这个编程任务让我难过,代码如下:
import java.awt.*;
import javax.swing.*;
public class HTree extends JPanel {
private Color color = new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256));
public void draw(Graphics g, int n, double sz, double x, double y) {
if (n == 0) return;
double x0 = x - sz/2, x1 = x + sz/2;
double y0 = y - sz/2, y1 = y + sz/2;
// draw the 3 line segments of the H
g.setColor(color);
g.drawLine((int)x0, (int)y, (int)x1, (int)y); …Run Code Online (Sandbox Code Playgroud) 我正在JPanel上画一条蓝线
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
super.paint(g2);
if (path.size() >= 2) {
BasisStroke stroke = new BasicStroke(Config.TILE_SIZE_IN_PIXEL / 3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
g2.setStroke(stroke);
g2.setPaint(Color.BLUE);
g2.setPaintMode();
for (int i = 0; i < path.size() - 1; i++) {
g2.drawLine(path.get(i).x, path.get(i).y, path.get(i + 1).x, path.get(i + 1).y);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我希望这条线是半透明的.我如何实现这一目标?
java ×6
swing ×3
jpanel ×2
android ×1
awt ×1
bitmap ×1
graphics2d ×1
jradiobutton ×1
line ×1
macos ×1
ondraw ×1
paint ×1
recursion ×1
translucency ×1
transparency ×1