android图片百叶窗实现方法
请教各位,初学,见谅!

解决方案 »

  1.   

    参照:SDK里面有例子Animation的翻页效果,
    不同的是,你的是百叶窗,不过是大同小异,你只需要将接触来的Bitmap按横坐标截图,存在一个数组里,每个被截的小图的4个点分别用一个含有4个元素的数组表示.从第一个页开始,每个小叶除了横坐标起始不同,变换的规律都是一样的.按照这个做法就Ok了,我没做过,不过这个办法应该可以.
      

  2.   

     
    导入包:
     
    import java.awt.*;
    import java.applet.*;
    import java.awt.image.*;
     
    实现代码:
     
    public class ShutterApplet extends Applet implements Runnable {
        // 待显示的图像数组及当前显示的图像
        Image images[], showImage;
        // 媒体装载器
        MediaTracker imageTracker;
        // 图像宽度,高度,总的图像数量,当前图像编号及下一个图像编号
        int imageWidth, imageHeight, totalImage = 5, currentImage, nextImage;
        // 图片切换效果的线程
        Thread thread;
        // 切换延迟
        int delay;
        // 图像点阵数及像素点数组
        int totalPix, pix1[], pix2[], pix3[], pix4[], pix5[], pixA[], pixB[];
     
        public void init() {
           // 设置Applet的背景颜色
           setBackground(Color.black);
           // 初始化数组
           images = new Image[totalImage];
           // 实例化媒体装载器
           imageTracker = new MediaTracker(this);
           // 参数字符串
           String param = new String("");
           // 得到所有图片
           for (int i = 0; i < totalImage; i++) {
               // 得到参数
               param = getParameter("image" + i);
               // 得到图像
               images[i] = getImage(getCodeBase(), param);
               // 加入图像到媒体装载器
               imageTracker.addImage(images[i], 0);
           }
           try {
               // 装载图像
               imageTracker.waitForID(0);
           } catch (InterruptedException e) {
           }
     
           // 得到延迟参数
           param = getParameter("delay");
           if (param != null) {
               delay = Integer.parseInt(param);
           } else {
               // 设置默认延迟参数
               delay = 2000;
           }
     
           // 得到图像宽度
           imageWidth = images[0].getWidth(this);
           // 得到图像高度
           imageHeight = images[0].getHeight(this);
           // 图像的总的像素点数量
           totalPix = imageWidth * imageHeight;
     
           pix1 = new int[totalPix];
           // 获取图像像素数据
           PixelGrabber pg1 = new PixelGrabber(images[0], 0, 0, imageWidth,
                  imageHeight, pix1, 0, imageWidth);
           try {
               // 抓取像素
               pg1.grabPixels();
           } catch (InterruptedException ex) {
           }
           pix2 = new int[totalPix];
           PixelGrabber pg2 = new PixelGrabber(images[1], 0, 0, imageWidth,
                  imageHeight, pix2, 0, imageWidth);
           try {
               pg2.grabPixels();
      &, ;nb, sp;    } catch (InterruptedException ex) {
           }
     
           pix3 = new int[totalPix];
           PixelGrabber pg3 = new PixelGrabber(images[2], 0, 0, imageWidth,
                  imageHeight, pix3, 0, imageWidth);
           try {
               pg3.grabPixels();
           } catch (InterruptedException ex) {
           }
     
           pix4 = new int[totalPix];
           PixelGrabber pg4 = new PixelGrabber(images[3], 0, 0, imageWidth,
                  imageHeight, pix4, 0, imageWidth);
           try {
               pg4.grabPixels();
           } catch (InterruptedException ex) {
           }
     
           pix5 = new int[totalPix];
           PixelGrabber pg5 = new PixelGrabber(images[4], 0, 0, imageWidth,
                  imageHeight, pix5, 0, imageWidth);
           try {
               pg5.grabPixels();
           } catch (InterruptedException ex) {
           }
     
           currentImage = 0;
           pixA = new int[totalPix];
           pixB = new int[totalPix];
           showImage = images[0];
        }
     
        public void start() {
           if (thread == null) {
               // 实例化线程
               thread = new Thread(this);
               // 运行线程
               thread.start();
           }
        }
     
        public void paint(Graphics g) {
           // 绘制当前图像
           g.drawImage(showImage, 0, 0, this);
        }
     
        public void update(Graphics g) {
           paint(g);
        }
     
        public void run() {
           while (true) {
               try {
                  // 线程休眠
                  thread.sleep(delay);
                  // 更改下一张图像编号
                  nextImage = ((currentImage + 1) % totalImage);
                  if (currentImage == 0) {
                      // 数组拷贝
                      System.arraycopy(pix1, 0, pixA, 0, totalPix);
                      System.arraycopy(pix2, 0, pixB, 0, totalPix);
                      // 转换像素数组到图像
                      showImage = createImage(new MemoryImageSource(imageWidth,
                             imageHeight, pixA, 0, imageWidth));
                      // 重绘屏幕
                      repaint();
                  } else if (currentImage == 1) {
                      System.arraycopy(pix2, 0, pixA, 0, totalPix);
                      System.arraycopy(pix3, 0, pixB, 0, totalPix);
                      showImage = createImage(new MemoryImageSource(imageWidth,
                             imageHeight, pixA, 0, imageWidth));
                      repaint();
                  } else if (currentImage == 2) {
                      System.arraycopy(pix3, 0, pixA, 0, totalPix);
                      System.arraycopy(pix4, 0, pixB, 0, totalPix);
                      showImage = createImage(new MemoryImageSource(imageWidth,
                             imageHeight, pixA, 0, imageWidth));
                      repaint();
                  } else if (currentImage == 3) {
                      System.arraycopy(pix4, 0, pixA, 0, totalPix);
                      System.arraycopy(pix5, 0, pixB, 0, totalPix);
                      showImage = createImage(new MemoryImageSource(imageWidth,
                             imageHeight, pixA, 0, imageWidth));
                      repaint();
                  } else if (currentImage == 4) {
                      System.arraycopy(pix5, 0, pixA, 0, totalPix);
                      System.arraycopy(pix1, 0, pixB, 0, totalPix);
                      showImage = createImage(new MemoryImageSource(imageWidth,
                             imageHeight, pixA, 0, imageWidth));
                      repaint();
                  }
                  while (true) {
                      for (int i = 0; i < (int) (imageHeight / 10); i++) {
                         try {
                             // 线程休眠
                             thread.sleep(80);
                             for (int j = 0; j < imageHeight; j += (int) (imageHeight / 10)) {
                                for (int k = 0; k < imageWidth; k++) {
                                    pixA[imageWidth * (j + i) + k] = pixB[imageWidth
                                           * (j + i) + k];
                                }
                             }
                         } catch (InterruptedException e) {
                         }
                         showImage = createImage(new MemoryImageSource(
                                imageWidth, imageHeight, pixA, 0, imageWidth)); //更新当前显示Image
                         repaint();
                      }
                      break;
                  }
                  currentImage = nextImage;
                  repaint();
               } catch (InterruptedException e) {
               }
           }
        }
    }
     
    HTML文件:
    <html>
    <head>
    <title>图片百叶窗</title>
    </head>
     
    <body>
        <applet code="ShutterApplet" width="250" height="150">
        <param name="image0" value="./AppletImg/STA_image0.jpg">
        <param name="image1" value="./AppletImg/STA_image1.jpg">
        <param name="image2" value="./AppletImg/STA_image2.jpg">
        <param name="image3" value="./AppletImg/STA_image3.jpg">
        <param name="image4" value="./AppletImg/STA_image4.jpg">
        <param name="delay" value="2000">
        </applet>
    </body>
    </html>
      

  3.   

    谢谢楼上的,但是对android的画图没理解。
    还没有搞定,求android代码~