3

我只是想获取用户选择的图像的路径,然后将其转换为位图。问题是,选择时只有画廊中的一些图像工作(通过“工作”,我的意思是它们被发现是一个存在的文件),而其他人声称该文件不存在(即使图像正在显示在画廊里?)。更奇怪的是,这似乎并不一致,曾经被认为“存在”的图像现在声称不存在。我的代码如下:

------意图-----

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_ACTIVITY);

-----onActivityForResult-----

Uri uri = intent.getData();
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(uri,proj,null,null,null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();

BitmapFactory.Options opts = new BitmapFactory.Options();<br/>
opts.inSampleSize = 2;<br/>
Bitmap b = BitmapFactory.decodeFile(cursor.getString(column_index),opts);

对此的任何想法将不胜感激,谢谢!

马特。

4

1 回答 1

0

图库中的某些图片是从外部来源(例如 Picasa)加载的,因此未存储在本地,导致本地文件路径读取失败。您可以通过读取您的 uri 值来区分它们。我找不到解决这个问题的方法,也许这个错误http://code.google.com/p/android/issues/detail?id=21234可以很快找到解决方案。

于 2012-01-08T07:45:50.803 回答