如何旋转JXImagePanel? [英] How to rotate JXImagePanel?
问题描述
我想旋转JXImagePanel。它应该是可能的 - 这是关于 JXImagePanel
:
I would to rotate JXImagePanel. It should be possible - this is about JXImagePanel
:
- Swing :: JXImagePanel
当 JLabel
和 JButton
时,您可以轻松地将图像添加到您的Swing应用程序,
JXImagePanel
使得添加任何 BufferedImage
或变得非常简单您的Swing应用程序的图标
。
While JLabel
and JButton
allow you to easily add images to your Swing applications,
the JXImagePanel
makes it trivially easy to add any BufferedImage
or Icon
to your Swing applications.
如果可以编辑,它还为用户提供了更改图像的方法。此外, JXImagePanel
提供了许多现成的内置效果,
包括 Tiling
,缩放
,旋转
,合成
等。
If editable, it also provides a way for the user to change the image. In addition, the JXImagePanel
provides many built in effects out-of-the-box,
including Tiling
, Scaling
, Rotating
, Compositing
, and more.
但是,我无法弄清楚如何做到这一点。目前我的代码片段是:
However, I cannot figure out how to do this. Currently my code snippet is:
bufferedImage = ImageIO.read(new File("image.png"));
image = new ImageIcon(bufferedImage).getImage();
tempImage = image.getScaledInstance(100, 150, Image.SCALE_FAST);
this.deskJXImagePanel.setImage(tempImage);
现在我想在 0-360 $ c中旋转它$ c>度。如何做到这一点?
Now I would like to rotate it in 0-360
degrees. How it can be done?
推荐答案
JXImagePanel已被弃用(实际上,从1.6.2开始使包私有,因为它仍然使用内部),所以最好不要使用,很快就会删除。
JXImagePanel is deprecated (actually, made package private as of 1.6.2, because it's still used internally), so better not use is, will be removed soon.
相反,使用带有ImagePainter的JXPanel和应用于画家的任意transformOp,在代码片段中喜欢:
Instead, use a JXPanel with an ImagePainter and an arbitrary transformOp applied to the painter, in code snippets something like:
JXPanel panel = new JXPanel();
ImagePainter image = new ImagePainter(myImage);
image.setFilters(
new AffineTransformOp(AffineTransform.getRotateInstance(-Math.PI * 2 / 8, 100, 100), null)
);
panel.setBackgroundPainter(image);
你可能需要玩一点才能获得你想要达到的确切效果。在问题上,您可能想尝试发布到Swinglabs论坛。
you'll probably have to play a bit to get the exact effects you want to achieve. On problems, you might want to try posting to the Swinglabs forum.
这篇关于如何旋转JXImagePanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!