2016-10-01 2 views
-6

[BLOB 이미지의 열 인덱스가 9,10,11이고 바이트 배열로 저장하는 sqlite 데이터베이스에서 BLOB를 가져옵니다. 나중에 비트 맵으로 변환하고 이미지 뷰로 설정합니다. 코드에 오류가 없습니다. 이미지 뷰는 이미지를 표시하지 않습니다. ][1]imageview에 비트 맵을 표시하는 방법 android에서 sqlite 데이터베이스에서 가져온

+0

비트 맵이 실제로 이미지를 검색합니까? 즉, 비트 맵이 null입니까? –

답변

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

관련 문제