显示ImageIcon的一部分 [英] Showing part of an ImageIcon
问题描述
Bonjour,
我正在尝试动画,并且发现自己在连续的单个图像上发现了一条爆炸。我希望他们按顺序依次显示爆炸动画。当然,我在 JLabel
上想 ImageIcon
,但当我查看 JLabel
spec我找到了这一行:
Bonjour,
I'm trying my hand at animation, and have found myself a strip of explosions on a single image in a row. I want them to show one after the other in sequence to animate an explosion. Naturally, I'm thinking ImageIcon
on JLabel
, but when I looked at the JLabel
spec I found this line:
JLabel(图标图标)
- 使用指定的图像创建JLabel
实例。标签在其显示区域中垂直和水平居中。
JLabel(Icon icon)
-- Creates aJLabel
instance with the specified image. The label is centered vertically and horizontally in its display area.
我希望能够仅显示部分完整图像标签,然后加载它的另一部分:基本上加载一个图像上的不同阶段。
I want to be able to show only part of a full image in the label, then load another part of it: basically loading the different stages on the one image.
有没有办法做到这一点,而无需切割图像并加载每个图像个别?
Is there a way to do this without cutting up the image and loading each one individually?
推荐答案
你可以最初使用 BufferedImage加载图像
,你可以调用 getSubimage
获取图片
的裁剪副本,同时保留原始图像
You could load the image initially using a BufferedImage
, whereby you could call getSubimage
to obtain a cropped copy of the Image
while retaining the original Image
这篇关于显示ImageIcon的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!