【发布时间】:2014-05-06 04:03:23
【问题描述】:
我想从相机拍摄图像,然后将图像保存在 SD 卡文件夹中,但路径保存在 SqLite 数据库中,并且还以二进制格式保存图像。同样,当从数据库读取时,在 ImageView 或 GridView 中显示图像。任何有关于此的资源或示例或教程链接。如果有人给我任何资源、示例或教程链接。这对我很有帮助。
【问题讨论】:
标签: android sqlite android-imageview android-image
我想从相机拍摄图像,然后将图像保存在 SD 卡文件夹中,但路径保存在 SqLite 数据库中,并且还以二进制格式保存图像。同样,当从数据库读取时,在 ImageView 或 GridView 中显示图像。任何有关于此的资源或示例或教程链接。如果有人给我任何资源、示例或教程链接。这对我很有帮助。
【问题讨论】:
标签: android sqlite android-imageview android-image
您可以将您的任务分成三个独立的部分:
1. Take a picture from camera
2. Save it to a file and take the path
3. Store the path from point two in your database
对于第 1 部分和第 2 部分:
final int IMAGE_FROM_CAMERA = 0;
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, IMAGE_FROM_CAMERA);
在 onActivityResult()...
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
String path = getRealPathFromURI(selectedImage);
}
...
public String getRealPathFromURI(Uri contentUri) {
String path = null;
String[] proj = { MediaStore.MediaColumns.DATA };
Cursor cursor = getContentResolver().query(contentUri, proj, null,
null, null);
if (cursor.moveToFirst()) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(column_index);
}
cursor.close();
return path;
}
对于第 3 部分,只需将字符串 path 写入数据库中的相应字段即可。因为打开很容易,因为您有路径,只需从路径中打开一个流,进行一些转换并获取您的图像。
【讨论】: