
public static Image createThumbnail(Image image,int width)
{
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
int thumbWidth = width;
int thumbHeight = -1;
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();

for (int y = 0; y < thumbHeight; y++)
{

for (int x = 0; x < thumbWidth; x++)
{
g.setClip(x, y, 1, 1);//設置該像素點以外的區域繪制無效
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy,Graphics.LEFT | Graphics.TOP);//重繪整張圖,實際上只是重繪了一個像素點
}
}
return thumb;
}
上面的代碼用來在J2ME中繪制圖片的縮略圖,CLDC1.0的用法,2.0可以直接操控像素了
---------------------------------------------------------
專注移動開發
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2009-12-19 15:42
TiGERTiAN 閱讀(1412)
評論(0) 編輯 收藏 所屬分類:
Java 、
J2ME