2011-11-22 139 views
1

我有一个图像对象,它是由相机拍摄的jpg图片,我需要从中创建一个位图。从图像创建位图

除了使用BMPGenerator类之外,还有什么办法可以做到吗?我正在开展一个商业项目,由于GPLv3许可证,我认为我不能使用它。

到目前为止,这是我的代码。我可以用它做点什么吗?

FileConnection file = (FileConnection) Connector.open("file://" + imagePath, Connector.READ_WRITE); 
    InputStream is = file.openInputStream(); 
    Image capturedImage = Image.createImage(is); 

我试过,但我没能得到正确的filepaht和图像卡在空

EncodedImage image = EncodedImage.getEncodedImageResource(filePath); 
    byte[] array = image.getData(); 
    capturedBitmap = image.getBitmap(); 
+1

是什么样的Image对象呢?一个PNG,一个像素阵列? – donturner

+0

已编辑。感谢您提问 –

回答

0

固定!好吧,差不多。 使用以下方法,但图像旋转90度。 要用this来修复

public Bitmap loadIconFromSDcard(String imgname){ 

    FileConnection fcon = null; 
    Bitmap icon = null; 

    try { 

     fcon = (FileConnection)Connector.open(imgname, Connector.READ); 
     if(fcon.exists()) { 
      byte[] content = new byte[(int) fcon.fileSize()]; 
       int readOffset = 0; 
       int readBytes = 0; 
       int bytesToRead = content.length - readOffset; 
       InputStream is = fcon.openInputStream(); 
       while (bytesToRead > 0) { 
       readBytes = is.read(content, readOffset, bytesToRead); 
       if (readBytes < 0) { 
        break; 
       } 
       readOffset += readBytes; 
       bytesToRead -= readBytes; 
       } 
       is.close(); 
      EncodedImage image = EncodedImage.createEncodedImage(content,0,content.length); 
      icon = image.getBitmap(); 

     } 

    } catch (Exception e) { 

    }finally{ 
     // Close the connections 
     try{ if(fcon != null) fcon.close(); } 
     catch(Exception e){} 
    } 

    return icon; 
} 
6

您可以使用videoControl.getSnapshot(null),然后Bitmap myBitmap = Bitmap.createBitmapFromBytes(raw, 0, raw.length, 1),从相机的位图。

视频监控从player.getControl("VideoControl")得到和playerManager.createPlayer()

了顺便说一句,你有什么样的形象?如果我们正在谈论EncodedImage,那么您可以使用它的getBitmap()

+0

谢谢,+1但是.... 我尝试过使用EncodedImage,但无法获得正确的文件路径。请选择以下代码并将代码添加到问题 EncodedImage image = EncodedImage.getEncodedImageResource(filePath); byte [] array = image.getData(); capturedBitmap = image.getBitmap(); –