我遵循 Android 开发人员的示例,从相机 Intent 中获取图像并将其放置在您的 View 中。当我尝试将该图像 uri 保存在我的 SqliteDatabase
上(只是该图像的链接而不是完整图像,因此我节省空间)然后我尝试在我的自定义适配器上恢复它时,问题就开始了。 p>
链接到google dev -> http://developer.android.com/training/camera/index.html
我尝试过,但没有成功
创建了一个全局字符串 Logo ,并将其放入handleSmallCameraPhoto
内
private void handleSmallCameraPhoto(Intent intent) {
Bundle extras = intent.getExtras();
mImageBitmap = (Bitmap) extras.get("data");
ImagenViaje.setImageBitmap(mImageBitmap);
ImagenViaje.setVisibility(View.VISIBLE);
--> logo = extras.get("data").toString();
然后我将 Logo 存储在 SQLite 上,并尝试以这种方式在我的适配器上恢复它
String imagePath = c.getString(c.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_LOGO_PATH));
然后
ImageView item_image = (ImageView) v.findViewById(R.id.logo);
item_image.setVisibility(ImageView.INVISIBLE);
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
item_image.setImageBitmap(bitmap);
item_image.setVisibility(ImageView.VISIBLE);
最佳答案
使用获取图像路径
Uri selectedImageUri = intent.getData();
String s1 = intent.getDataString();
String selectedImagePath = getPath(selectedImageUri);
if(selectedImagePath==null && s1 != null)
{
selectedImagePath = s1.replaceAll("file://","");
}
在你的handleSmallCameraPhoto
方法中
将此方法添加到您的 Activity 中
public String getPath(Uri uri) {
try{
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor==null)
{
return null;
}
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
catch(Exception e)
{
return null;
}
}
将selectedImagePath
保存在数据库中并在需要时使用selectedImagePath
是所选图像的路径
希望能帮到你..
关于java - Android 从相机获取图像 Uri,存储在 SQLite 中并将其恢复到我的自定义适配器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11843892/