Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

java - How to rotate JXImagePanel?

I would to rotate JXImagePanel. It should be possible - this is about JXImagePanel:

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.

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);

Now I would like to rotate it in 0-360 degrees. How it can be done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...