1

我按照 Android 开发人员示例从相机意图中获取图像并将其放置在您的视图中。当我尝试将图像 uri 保存在我的SqliteDatabase(只是指向该图像的链接而不是完整图像,因此我节省空间)然后我尝试在我的 customadapter 上恢复它时,问题就开始了。

链接到谷歌开发 - > http://developer.android.com/training/camera/index.html

我试过这个没有成功

创建了一个全局字符串徽标,并在里面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();

然后我将徽标存储在 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);
4

1 回答 1

0

使用获取图像路径

Uri selectedImageUri = intent.getData();
String s1 = intent.getDataString(); 

String selectedImagePath = getPath(selectedImageUri);
if(selectedImagePath==null && s1 != null)
{
    selectedImagePath = s1.replaceAll("file://","");
}

在你的handleSmallCameraPhoto方法中

在您的活动中添加此方法

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所选图像的路径

希望能帮到你。。

于 2012-08-07T11:11:39.593 回答