程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> MIDP1.0的圖片放縮(setClip實現)

MIDP1.0的圖片放縮(setClip實現)

編輯:J2ME
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秒 。 (呵呵)
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved