我知道如何创建半透明窗口,但我只是为了完整性而将其包括在内。
现在这就是我正在尝试做的......
创建一个不透明度为 60% 的未修饰 JFrame
软窗口边缘。
引用上图,您可以看到边缘清晰且轮廓分明。我想让它们变软
给它一个圆角矩形形状。
我可以使用AWTUtilities.setWindowShape(Window,Shape)
给出形状,但我想知道如何创建圆角矩形。
创建`BufferedImage`的反射以用作背景
你为什么不使用 Photoshop?你可能会问,但为你想尝试用作背景的每张图像创建反射是很乏味的。相反,我想知道是否有一种编程方式可以:
BufferedImage
JFrame
的大小设置为原始缓冲图像的两倍救命!!!
<小时/>import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class ImageReflection extends JFrame{
public ImageReflection(){
ImageIcon baseIcon = new ImageIcon("src/images/mentalist-logo.png");
ImageIcon reflectIcon = new ImageIcon("src/images/mentalist-logo.png");
JLabel baseLabel = new JLabel(baseIcon);
JLabel reflectLabel = new JLabel();
Graphics2D g2D = (Graphics2D) reflectIcon.getImage().getGraphics();
g2D.rotate(180);
reflectLabel.setIcon(reflectIcon);
this.add(reflectLabel);
this.setVisible(true);
this.pack();
}
public static void main(String[] args) {
new ImageReflection();
}
}
我在 Graphics2D g2D = (Graphics2D)reflectIcon.getImage().getGraphics();
处收到 UnsupportedOperationException
。
这是我将图像翻转的代码。
最佳答案
What is left is creating a reflection.
您可以像这样更改图形上下文的AffineTransform
:
BufferedImage newImage = new BufferedImage(
oldImage.getWidth(), oldImage.getHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = newImage.createGraphics();
g2d.translate(0, newImage.getHeight());
g2d.scale(1, -1);
g2d.drawImage(oldImage, 0, 0, null);
g2d.dispose();
关于java - 创建自定义 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14054951/