-6
[我从我的sqlite数据库检索blob图像的列索引是9,10,11并将它们存储为字节数组blob。稍后转换为位图并设置为图像视图。代码中没有错误。但imageview不显示图像。 ][1]如何显示位图上的图像取自sqlite数据库android
[我从我的sqlite数据库检索blob图像的列索引是9,10,11并将它们存储为字节数组blob。稍后转换为位图并设置为图像视图。代码中没有错误。但imageview不显示图像。 ][1]如何显示位图上的图像取自sqlite数据库android
看看这个代码: 你必须从光标加载图像字节并将其转换为位图。
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);
}
谢谢你..它帮了我很多 – Soumya
是位图真的检索图像,即位图为空? –