a sniplet from the article "taking pictures with mmapi"
http://developers.sun.com/techtopics/mobility/midp/articles/picture/
clapton_xp@hotmail.com
创建缩略图
midp2.0中可以对图片中的像素进行操作,在midp1.0中则不然。本例用graphics.setclip()实现每一次对一个像素进行绘制。
private image createthumbnail(image image) {
int sourcewidth = image.getwidth();
int sourceheight = image.getheight();
int thumbwidth = 64;
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);
}
}
image immutablethumb = image.createimage(thumb);
return immutablethumb;
}
