2013-10-30 31 views
0
byte[] imageInByte; 
ImageView iViewAddImage; 

if (imageInByte.length>0) { 
    Bitmap bitmap = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length); 
    iViewAddImage.setImageBitmap(bitmap); 
} 

我得到BitmapnullimageInByte.length=20621解码时给出null的位图?

什么在做错。让我难过?

编辑1:

public void insertImage(byte[] imageInByte2) 
{ 
    if(sqliteDb != null) 
    { 
     try { 
      sqliteDb.insert("database",null,getDataValues(imageInByte2)); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

    private ContentValues getDataValues(byte[] imageInByte2){ 
    ContentValues contentValues = new ContentValues(); 

    try { 
     contentValues.put("image",imageInByte2); 

    } 
    catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return contentValues; 
    } 
+1

?试试'byte [] imageInByte = new byte [1024];' – GrIsHu

+0

看到这个。 http://stackoverflow.com/questions/6520745/why-does-bitmapfactory-decodebytearray-return-null – blitzen12

+0

你需要将图像转换为字节数组,然后只添加它进行解码。 – GrIsHu

回答

0

这可能帮助你

byte imageinbyte[]; 
bitmap bmp; 
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
       bmp.compress(Bitmap.CompressFormat.JPEG, 100, bos); 
       imageInByte = bos.toByteArray(); 

您可以直接设置您已经于您的字节数组累加图像的字节的图像视图背景

ImageView.setImageBitmap(bmp);|