您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> js >> 正文

J2ME中对Image的缩放

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-27 我要参与讨论

  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;

}

在google里搜索更多J2ME中对Image的缩放

Google
Web www.51ec.org
  • 上一篇信息学院:

  • 下一篇信息学院:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    我来说两句 对此文章发表了评论
      昵 称: *必填    ·注册用户·
      评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
    评 论
    内 容

     
    评论列表 (最新 评论仅限网友观点!)

    推荐文章
  • 此栏目下没有推荐信息学院
  • 供求信息




    | 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明