2011-03-23 112 views
0

我想在編碼的圖像上畫一條線,這樣我會得到一個新的圖像。如果你願意,你可以給我關於這方面的信息嗎? 非常感謝。 這裏我給我的代碼,我得到了編碼的圖像。如何在bb中的編碼圖像上繪製一條線?

String URL = "http://maps.google.com/maps/api/staticmap?center=" 
     + centerX + "," + centerY + "&zoom=15&size=480x320&" 
     + "path=color:0x0000ff|weight:5" + path 
     + "&maptype=roadmap&sensor=true;deviceside=true"; 

      try { 
       conn = (HttpConnection) Connector.open(URL); 
       stream = conn.openInputStream(); 
       byteArray = new ByteArrayOutputStream(); 
       int dataToWrite = 0; 
       while ((dataToWrite = stream.read()) != -1) { 
        byteArray.write(dataToWrite); 
       } 
       byte[] bArray = byteArray.toByteArray(); 
       EncodedImage image = 
        EncodedImage.createEncodedImage(bArray, 0, bArray.length); 
       imageBitmap = image.getBitmap(); 
       vfm.deleteAll(); 
       bitField = new BitmapField(imageBitmap); 
       vfm.add(bitField); 
+0

您可能已經考慮過這一點,但請注意Google的靜態地圖API明確禁止在網絡瀏覽器之外顯示靜態地圖,除非您是Google Maps API Premier客戶:http://code.google.com/apis/ maps/documentation/staticmaps /#概述 – 2011-03-24 16:58:30

回答

1
  1. 創建Graphics對象

    Graphics graphics = new Graphics(imageBitmap); 
    
  2. 調用Graphics.drawLine()上繪製該位圖線。

    graphics.drawLine(x1,y1,x2,y2); 
    

現在imageBitmap是線新位圖。

+0

或者在BB 4.7+中,其中構造函數已被棄用,請改用'Graphics.create(imageBitmap)'。 – 2011-03-24 13:34:43

相關問題