我需要在另一个图像中剪切出文本形状的图像.我认为它最好显示在图像中.
这是一张猫的照片:

这是我要删除的文字:

生成的图像是这样的:

文本图像将始终为黑色并具有透明背景,并且生成的剪切图案也应具有透明背景.两个输入图像也将具有相同的大小.
我有从Myanel扩展的类MyPanel.MyPanel类具有JLabel组件,其中包含一个图标.
我的问题是如何在MyPanel类中绘制/渲染此JLabel组件以获得半透明效果(请参阅图标)(不创建xxxJLabel扩展JLabel类并覆盖paintComponents方法).
谢谢
为什么以下代码显示黑色图像而不是图片?如何正确扩展BufferedImage?
class SizeOfImage {
public static void main(String[] args) throws Exception {
URL url = new URL("http://cloudbite.co.uk/wp-content/uploads/2011/03/google-chrome-logo-v1.jpg");
final BufferedImage bi = ImageIO.read(url);
final String size = bi.getWidth() + "x" + bi.getHeight();
final CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JLabel l = new JLabel(size, new ImageIcon(cstImg), SwingConstants.RIGHT);
JOptionPane.showMessageDialog(null, l);
}
});
}
public static class CustomImg extends BufferedImage {
public CustomImg(int width, int height, int type){
super(width, height, type);
}
}
}
Run Code Online (Sandbox Code Playgroud)