如何检索存储在我的数据库中的图像作为真实图像,我已经使用两种不同的方法从数据库中获取图像,但没有一个适合我。
我有这个类,我正试图从listview中检索数据库中的图像。
在编译项目时,我收到以下内容:
resolveUri在坏位图uri上失败了
这是我的课程之一:
public class ListProp extends ListActivity {
private static final String TAG = ListProp.class.getSimpleName();
private static final String TAG_PHOTOS = "photoThumbnailUrl";
private SQLiteDatabase database;
private CursorAdapter dataSource;
Cursor cursor;
private static final String fields[] = { "photoThumbnailUrl",
BaseColumns._ID };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBHelper helper = new DBHelper(this);
database = helper.getReadableDatabase();
database = helper.getWritableDatabase();
Cursor data = database.query(DBHelper.TABLE, fields, null, null, null,
null, null);
dataSource = new SimpleCursorAdapter(this, R.layout.image, data,
fields, new int[] { R.id.image1 });
setListAdapter(dataSource);
System.out.println(dataSource);
database.close();
// selecting single ListView item
final ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
System.out.println("I'm fine here");
ImageView image = (ImageView) findViewById(R.id.image1);
// get it as a ByteArray
while (cursor.moveToFirst())
;
byte[] imageByteArray = cursor.getBlob(cursor
.getColumnIndex(DBHelper.C_PHOTOS));
// convert it back to an image
ByteArrayInputStream imageStream = new
ByteArrayInputStream(imageByteArray);
Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
Drawable d = new BitmapDrawable(bitmap);
image.setImageResource(R.drawable.ic_launcher);
cursor.close();
lv.addView(image);
}
});
}
}
请尝试以下教程:http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html
您将不得不使用BitmapFactory函数decodeByArray:
.setImageBitmap(BitmapFactory.decodeByteArray
希望这可以帮助
• 如何使用 express js 在 mongodb 中存储布尔值
• 将 ASP Classic 代码作为字符串存储在 MYSQL 数据库中的可能性 [重复]
• Thymeleaf {'data:image/jpeg;base64'} 用于显示数据库图像的语法不起作用
• 如何使用 SwiftUI 和 Xcode for macOS/
• 如何使用 ado.net 从输入文件中获取文件,然后向服务器发送请求并将此文件存储在 SQL Server 数据库中的 varbinary 列中?
• Flutter 如何从本地存储加载图片到 ByteData?
• 如何将 IEnumerable<Task<string>> 转换为 IEnumerable<string>?
• 如何转换在 Javascript 数组中存储为字符串的整个数字数组?