随笔-348  评论-598  文章-0  trackbacks-0
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, 
11);//设置该像素点以外的区域绘制无效
        
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 阅读(1394) 评论(0)  编辑  收藏 所属分类: JavaJ2ME

只有注册用户登录后才能发表评论。


网站导航: