如何将Icon从JLabel转换为BufferedImage? [英] How to convert Icon from JLabel into BufferedImage?
问题描述
简单,非常直接但似乎叔叔谷歌和我感到困惑。
Simple, very straight forward but seems uncle google and me getting confused.
我有单个 JLabel
那个已经拥有自己的图标
。
I have single JLabel
that already has its own Icon
.
如何转换图标
从 JLabel
获得 BufferedImage
?
有没有办法:我尝试了多次投射这样..
Is there any way around: I tried to multiple casting like this ..
final BufferedImage bf1 = (BufferedImage)((Image)jll_img.getIcon());
..但失败了。
推荐答案
放大@Andrew Thompson的回答,请注意实现 图标
界面知道如何绘制某些东西,但可能还没有要求它这样做。相比之下, BufferedImage 程序必须通过调用 paintIcon()
方法呈现的图像数据的可访问缓冲区。这是一个相关的示例。
To amplify on @Andrew Thompson's answer, note that an object that implements the Icon
interface knows how to paint something, but it may not have been asked to do so yet. In contrast, a BufferedImage has "an accessible buffer of image data" that your program must render by calling the paintIcon()
method. Here's a related example.
这篇关于如何将Icon从JLabel转换为BufferedImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!