MIDP 1.0 的图片放缩, setClip实现

来源:互联网 发布:欠淘宝3000会判刑吗 编辑:程序博客网 时间:2024/06/05 01:51

 

public Image resizeImage(Image image, int scale) {//scale 是放缩比率哈, 100是正常大小

        int sWidth = image.getWidth();

        int sHeight = image.getHeight();

        int Width = sWidth * scale / 100;

        int Height = Width * sHeight / sWidth;
      
        Image img = Image.createImage(Width, Height);
        
        Graphics g = img.getGraphics();

        for (int y = 0; y < Height; y++) {
            for (int x = 0; x < Width; x++) {
                g.setClip(x, y, 1, 1);
                int dx = x * sWidth / Width;
                int dy = y * sHeight / Height;
                g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
            }
        }
        return img;
    }

OT557上放缩140*140的图片大约需要6秒。 (破机器哈, 最好不要在V878一样的机器上用哈, 那将是NIGHTMARE!

7610上放缩140*140的图片需要1到2秒 。  (过得去哈

K700上放缩140*140的图片需要1秒 。   (呵呵

 

原创粉丝点击