求高人写一个函数,参数是一个Image,返回的是一个将原图片左右翻转的Image.

解决方案 »

  1.   

    hjnmn,
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    hjnmn,
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  3.   

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    int xRot = this.getWidth() / 2;
    int yRot = this.getHeight() / 2;
    newXform.rotate(Math.toRadians(currentAngle), xRot, yRot);
    g2d.setTransform(newXform);
    int x = (getWidth() - image.getWidth(this)) / 2;
    int y = (getHeight() - image.getHeight(this)) / 2;
    g2d.drawImage(image, x, y, this);
    g2d.setTransform(origXform);
      

  4.   

    我是这样做了一个函数    不知道专业不   呵呵....
    public Image getFlippedPicture(Image srcImage){
    AffineTransform t = new AffineTransform(-1,0,0,1,srcImage.getWidth(null),0);
    BufferedImage newImage = new BufferedImage(srcImage.getWidth(null),srcImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = (Graphics2D)newImage.getGraphics();
    gr.drawImage(srcImage, t, null);
    return (Image)newImage;
    }
      

  5.   

    如果能附上全部代码,让象我这样的菜鸟学习下就好了,自学java不容易啊!
      

  6.   

    还可以用一个方法,把图像用raster加载入一个数组data[imageWidth][imageHeight](这个数组的数据是按照图像的行和列的数据来存放的,这个java的raster已经为我们做好了,不用我们去做),然后对这个数组内的数据进行变化,如data[i][j] = data[imageWidth - 1 - i][j];就是把图像倒过来。用这种方法你可以对图像进行任何变化,进行图像像素的插值,blur,几幅图像合成新的图像。第一步是把图像光删化为数据存入data[imageWidth][imageHeight]中,用PixelGrabber
    第二步是把这个数组中的数据用ImageProducer来生成新的图像,然后画到窗口中。这是以前写过的,具体的步骤和代码在帮助文档中有,不过也可以去网上找一下别人的例子。
      

  7.   

    别人写的代码,我也是刚看过的,希望对你有帮助
    import java.awt.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.image.*;//图片翻折public class TurnApplet extends Applet implements Runnable{
      Image images[],showImage;  //图像数组及当前显示图像
      MediaTracker imageTracker;  //加载图像的MediaTracker对象
      int imageWidth,imageHeight,currentImage,totalImage; //图像宽度,高度,当前图像编号,图像总的个数
      Thread thread; //图片翻折线程
      int delay;  //翻折延迟
      Image image;  //绘制图像的Image对象
      Graphics graphics;  //绘制图像的Grahpics对象
      
      public void init(){
       totalImage = 5; //初始化参数
       currentImage = 0;
        setBackground(Color.white);  //设置背景颜色   
        images = new Image[totalImage]; 
        imageTracker = new MediaTracker(this);   //得到MediaTracker实例
        String param ;
        for(int i=0; i<totalImage; i++) {
          param = getParameter("image" + (i+1)); //得到参数
          images[i] = getImage(getCodeBase(),param); //得到图像
          imageTracker.addImage(images[i],0); //增加图片到加载器中
        }
        try {
          imageTracker.waitForID(0); //加载图像
        }
        catch(InterruptedException e) {}
        
        param=getParameter("delay");  //得到延迟参数
        if(param== null){
          delay = 3000; //设置默认参数
        }
        else {
          delay = Integer.parseInt(param);
        }    
        imageWidth = images[0].getWidth(this);  //得到图像宽度
        imageHeight = images[0].getHeight(this);    //得到图像高度 
        image = createImage(imageWidth,imageHeight); //创建Image实例
        graphics = image.getGraphics();  //得到Graphics实例
      }
      
      public void start() {
        if(thread == null) {
          thread = new Thread(this);  //实例化线程
          thread.start(); //运行线程
        }
      }
      public void paint(Graphics g) {
        g.drawImage(image,0,0,this); //绘制图像
      }
      
      public void update(Graphics g) {
        paint(g);
      }
        
      public void run() {
        while(thread != null) {
          try{     
            for(int i=0; i<=(imageHeight/2); i++) {  //实现图片的翻折效果
              thread.sleep(30);  //线程休眠,实现图像的逐渐翻转
              graphics.setColor(Color.white); //设置当前颜色
              graphics.fillRect(0,0,imageWidth,imageHeight); //绘制填充矩形
              graphics.drawImage(images[currentImage],0,i,imageWidth,imageHeight-2*i,this); //以不同高度绘制图片
              repaint(); //重绘屏幕
            }
            
            currentImage = ((currentImage+1)%totalImage); //更改当前图像编号值
            
            for(int i=0; i<=(imageHeight/2); i++){ //实现图片的反向翻折效果
              thread.sleep(30);
              graphics.setColor(Color.white);
              graphics.fillRect(0,0,imageWidth,imageHeight);
              graphics.drawImage(images[currentImage],0,(imageHeight/2)-i,imageWidth,2*i,this);
              repaint();
            }
             thread.sleep(delay);  //线程休眠         
          }
          catch(InterruptedException e){}
        }
      }
    }