다운로드 앱 목록 중 선택된 앱의 아이콘을 db에 저장해서 화면에 뿌리려고 합니다.
구글링을 해보니 byte[]로 db에 저장한 뒤 꺼낼 때 bitmap이나 drawable로 뿌려준다고 하면 된다고 하더군요
그래서
public static Drawable getDrawableFromByteArray(byte[] b) {
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
return new BitmapDrawable(context.getResources(), bitmap);
}
public byte[] getByteArrayFromDrawable(Drawable d) {
Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(),
d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
이렇게 2개 함수를 사용했습니다.
db생성은 Create table ... icon BLOB.. 로 했습니다.
그런데 Factory returned null 라는 오류가 뜨네요.. 원인좀 알 수 있을까요? ㅠㅠ