2012-01-17 40 views
0

失敗,我試圖做一個相關圖片如下: -圖像創作的MIDlet

try 
    { 
     strom = Image.createImage("stromB.png"); 
     map0 = Image.createImage("map0.png"); 
    } 
    catch (Exception e) 
    { 
     System.out.println("image creatino faild"); 
     System.out.println(e.getMessage()); 
    } 

strom工作正常,但map0總是拋出異常。我的猜測是尺寸更大,可能是這個原因。

  • 如何在midlet中使用較大的png圖像?
  • midlet是否有任何限制?
  • 我可以用於midlet的最大尺寸是多少?
+0

什麼是例外,是因爲尺寸較大,使用下面的方法來較大的圖像來調整呢? – 2012-01-17 18:07:39

回答

0

map0拋出異常可以根據屏幕大小

/** 
    * This methog resizes an image by resampling its pixels 
    * @param src The image to be resized 
    * @return The resized image 
    */ 

    private Image resizeImage(Image src) { 
     int srcWidth = src.getWidth(); 
     int srcHeight = src.getHeight(); 
     Image tmp = Image.createImage(screenWidth, srcHeight); 
     Graphics g = tmp.getGraphics(); 
     int ratio = (srcWidth << 16)/screenWidth; 
     int pos = ratio/2; 

     //Horizontal Resize   

     for (int x = 0; x < screenWidth; x++) { 
      g.setClip(x, 0, 1, srcHeight); 
      g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP); 
      pos += ratio; 
     } 

     Image resizedImage = Image.createImage(screenWidth, screenHeight); 
     g = resizedImage.getGraphics(); 
     ratio = (srcHeight << 16)/screenHeight; 
     pos = ratio/2;   

     //Vertical resize 

     for (int y = 0; y < screenHeight; y++) { 
      g.setClip(0, y, screenWidth, 1); 
      g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP); 
      pos += ratio; 
     } 
     return resizedImage; 

    }//resize image  
+0

圖像有文字通知一些東西。所以我無法調整圖像以適應較小的屏幕。我的意圖是繪製完整的圖像而不包含大小。我將在用戶按鍵事件後將其移動一點點。我沒有找到任何選擇如何通過使用j2me API來移動畫布。請拋出一些光線來實現我的任務。 – masiboo 2012-01-19 12:05:47

+0

使用圖像的位置(x和y)根據您的情況在右側,左側或任何位置移動圖像... – 2012-01-23 11:35:12