2012-03-20 90 views
0

我使用下面的代码从字符串获取位图,但我得到空位图。所以请指导我。字符串图像

    byte[] Image_getByte = Base64.decode(img); 

        ByteArrayInputStream bytes = new ByteArrayInputStream(Image_getByte); 

     BitmapDrawable bmd = new BitmapDrawable(bytes); 

     Bitmap bitmap=bmd.getBitmap(); 

     Log.v("log","Home bitmap "+bitmap); 

     i.setImageBitmap(bitmap); 
+0

我不知道,但我认为你应该使用的,而不是构造BitmapFactory.decodeStream。 – vorrtex 2012-03-20 05:50:15

回答

1

使用BitmapFactory.decodeByteArray(Image_getByte)

这里你不需要任何字符串,得到了字节数组后,只是通过它在返回位图

0
提到的方法

javadoc getBitmap()说:

“返回此drawable用于渲染的位图。 可能为空。

0

如果IMG是基地64字符串中使用下列来源获取从底部64串位图。

byte[] source=img.getBytes(); 
byte[] Image_getByte = Base64.decode(source); 
Bitmap bitmap = BitmapFactory.decodeByteArray(Image_getByte, 0,Image_getByte.length); 
imageView.setImageBitmap(bitmap); 

这可能会帮助你

0

请考虑 'ImageContents' 作为字符串其中包含图像数据

byte[] imageAsBytes = Base64.decode(ImageContents.getBytes()); 
    ImageView image = (ImageView)this.findViewById(R.id.ImageView); 
    image.setImageBitmap(
      BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length) 
    ); 

ImageView的:在Android中,可以用“android.widget.ImageView”类来 显示的图像文件

BitmapFactory:创建从各种来源的位图对象,包括 文件,流,和字节阵列。

有关BitmapFactory更多信息,请参阅here