2016-10-01 55 views

回答

0

看看这个代码: 你必须从光标加载图像字节并将其转换为位图。

byte[] imageBytes = getBlob(cursor, "ImageFieldName", null); 
if (imageBytes != null) 
{ 
    Bitmap bmp= convertByteArrayToBitmap(imageBytes); 
    imageview1.setImageBitmap(bmp); 
} 

private byte[] getBlob(Cursor cursor, String colName, byte[] defaultValue) { 
     try { 
      int colIndex; 
      if (cursor != null && (colIndex = cursor.getColumnIndex(colName)) > -1 
        && !cursor.isNull(colIndex)) 
       return cursor.getBlob(colIndex); 
      return defaultValue; 
     } catch (Exception e) { 
      e.printStackTrace(); 
      return defaultValue; 
     } 
    } 

private Bitmap convertByteArrayToBitmap(byte[] bytes) { 
     return BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
    } 
+0

谢谢你..它帮了我很多 – Soumya

相关问题