How to rotate JXImagePanel?(如何旋转 JXImagePanel?)
问题描述
我想旋转 JXImagePanel.应该有可能 - 这是关于 JXImagePanel
:
I would to rotate JXImagePanel. It should be possible - this is about JXImagePanel
:
- Swing :: JXImagePanel
虽然 JLabel
和 JButton
允许您轻松地将图像添加到 Swing 应用程序,JXImagePanel
使得将任何 BufferedImage
或 Icon
添加到 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
、Scaling
、Rotating
、Compositing
等等.
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 开始将包设为私有,因为它仍在内部使用),所以最好不要使用 is,很快就会被删除.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何旋转 JXImagePanel?


基础教程推荐
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01