如何旋转JXImagePanel? [英] How to rotate JXImagePanel?

查看:90
本文介绍了如何旋转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 度。如何做到这一点?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆