隨筆-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 閱讀(1412) 評論(0)  編輯  收藏 所屬分類: JavaJ2ME
          主站蜘蛛池模板: 衢州市| 武宣县| 红原县| 富平县| 盖州市| 东安县| 台东市| 苏州市| 锦屏县| 富平县| 科技| 淄博市| 天柱县| 祁阳县| 久治县| 石河子市| 藁城市| 鄂托克前旗| 华阴市| 隆安县| 灵川县| 余江县| 明水县| 托里县| 上饶县| 星座| 邹平县| 灵石县| 东源县| 岳普湖县| 山东省| 额敏县| 蚌埠市| 怀集县| 恭城| 视频| 太原市| 富裕县| 汕头市| 汕尾市| 湘潭县|