2013-10-30 34 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);|