Android 如何在数据库中存储图像?
我正在开发一个需要在数据库中存储图像的应用程序。我尝试过将图像转换为字节,但这是一个非常缓慢的过程。是否有其他方法将图像存储在数据库中您可以将图像路径存储到数据库中,将图像存储在SD卡中,并从数据库中的图像路径中检索图像您可以将图像路径存储到数据库中,将图像存储在SD卡中,并从中检索图像数据库中的图像路径您可以将图像路径以字符串格式存储在数据库中。您可以将图像路径以字符串格式存储在数据库中。获取图像表单sd卡Android 如何在数据库中存储图像?,android,Android,我正在开发一个需要在数据库中存储图像的应用程序。我尝试过将图像转换为字节,但这是一个非常缓慢的过程。是否有其他方法将图像存储在数据库中您可以将图像路径存储到数据库中,将图像存储在SD卡中,并从数据库中的图像路径中检索图像您可以将图像路径存储到数据库中,将图像存储在SD卡中,并从中检索图像数据库中的图像路径您可以将图像路径以字符串格式存储在数据库中。您可以将图像路径以字符串格式存储在数据库中。获取图像表单sd卡 if (requestCode == SD_REQUEST) { Uri select
if (requestCode == SD_REQUEST) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
testimage.setImageBitmap(yourSelectedImage);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
}
保存图像
DatabaseAdapter dbHelper = new DatabaseAdapter(Profiles.this);
dbHelper.open();
dbHelper.createUserProfiles( byteArray);
dbHelper.close();
现在在DatabaseAdapter.java中
定义
public static final String U_PIC = "picture";
然后
从sd卡获取图像
if (requestCode == SD_REQUEST) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
testimage.setImageBitmap(yourSelectedImage);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
}
保存图像
DatabaseAdapter dbHelper = new DatabaseAdapter(Profiles.this);
dbHelper.open();
dbHelper.createUserProfiles( byteArray);
dbHelper.close();
现在在DatabaseAdapter.java中
定义
public static final String U_PIC = "picture";
然后
我建议正常存储图像,然后在数据库中指定文件名和位置。我不知道androids是如何工作的,但你不能只将图像名存储在数据库中,并将图像存储在某种目录中吗?我建议正常存储图像,然后在数据库中指定文件名和位置。我不知道androids是如何工作的,但是你能不能把图像名存储在数据库中,把图像存储在某种目录中?