如果您從視頻獲取縮略圖對象,則需要將其保存在存儲或數據庫中。
要保存在數據庫:
public static synchronized Bitmap getImage(String imageID, Context context) {
SQLiteDatabase writableDb; // Get it with your approach
Bitmap bitmap = null;
Cursor cs = null;
try {
String sql = "SELECT BYTES FROM TABLE_NAME WHERE IMAGEID = ?;";
cs = writableDb.rawQuery(sql, new String[]{imageID});
if (cs != null && cs.moveToFirst()) {
do {
byte[] bytes = cs.getBlob(0);
if (bytes != null) {
try {
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} catch (Exception e) {
Log.e("TAG", "Exception", e);
}
} else {
Log.e("TAG", "IMAGE NOT FOUND");
}
} while (cs.moveToNext());
}
} catch (Exception e) {
Log.e("TAG", "Exception", e);
} finally {
if (cs != null) {
cs.close();
}
}
return bitmap;
}
數據庫結構:
String imageTable = "CREATE TABLE TABLE_NAME("
+ "IMAGEID TEXT PRIMARY KEY, "
+ "BYTES BLOB)";
Bitmap thumbnailBitmap; // Get it with your approach
SQLiteDatabase writableDb; // Get it with your approach
if (thumbnailBitmap != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
thumbnailBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] thumbnailBitmapBytes = stream.toByteArray();
ContentValues values = new ContentValues();
values.put("IMAGEID", "your_image_id");
values.put("BYTES", thumbnailBitmapBytes);
writableDb.insert("TABLE_NAME", null, values);
}
從數據庫中找回來