欢迎光临
我们一直在努力

J2ME中对Image的缩放-JSP教程,J2ME开发

建站超值云服务器,限时71元/月

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;

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » J2ME中对Image的缩放-JSP教程,J2ME开发
分享到: 更多 (0)

相关推荐

  • 暂无文章