现在有这样的一种情况,我在图片上进行了一些操作,比方说,画圆,画矩形,写些文字,我现在要翻转图片,因此,这些文字,矩形,也要跟着翻转,请问,你们是怎么实现的哦?

解决方案 »

  1.   

    这是我做的一个程序,我在图片表面增加了一个矩形,我发现,图片是可以实现翻转,但矩形是没有做相应的翻转,请问,谁能解决哦?
    package com.swing.japplet;import java.applet.*;
    import java.awt.*;
    import java.awt.geom.*;import javax.imageio.*;
    import java.io.*;public class ImageTest extends Applet {
    private Image image;
    AffineTransform at = new AffineTransform(); public void init() {
    // 文件位置
    String filename = "F:/workspace/Test/src/pic/1x.jpg";
    // 文件读入
    try {
    image = ImageIO.read(new File(filename));
    } catch (IOException e) {
    e.printStackTrace();
    } }
    public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    int width = image.getHeight(this);
    int height = image.getHeight(this);
    g2D.setColor(Color.BLACK);
    g2D.fillRect(0, 0, getSize().width, getSize().height);
    AffineTransform trans = new AffineTransform();
    trans.setToIdentity();
    // 坐标变换
    trans.translate(width / 2, height / 2);
    trans.scale(1, 1);
    // 旋转90度
    trans.rotate(Math.toRadians(360));
    trans.translate(-width / 2, -height / 2);
    g2D.drawImage(image, trans, this);

          Rectangle2D rect = new Rectangle2D.Double(100 ,
    150 , 90, 180 );       g2D.draw(rect);// 首先创建一实现了shape接口的类对象rect,然后调用Graphics2D的draw }}
      

  2.   

     
    Graphics g = image.getGraphics();
    g.drawRect(100 ,150 , 90, 180 );trans ...