【发布时间】:2012-03-05 23:28:48
【问题描述】:
我正在尝试为我目前在市场上的应用程序发布关键更新。我需要查询 MediaStore 中的缩略图,并将缩略图加载到 GridView 中。到目前为止一切顺利,现在我只需要根据我所拥有的(即缩略图的路径)来获取用户外部存储上实际全尺寸图像的路径。每当用户单击缩略图、共享、查看、移动和删除时,我都需要能够执行 4 个操作……但我无法仅使用缩略图路径来执行任何这些操作,我已经尝试了所有操作,但没有工作 :/。下面是我的实现的一个 sn-p,对此的任何帮助或指导将不胜感激!
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
int columnIndex = 0;
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null);
if(cursor != null){
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
imagePath = cursor.getString(columnIndex);
FileInputStream is = null;
BufferedInputStream bis = null;
try{
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
useThisBitmap = Bitmap.createScaledBitmap(bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
}catch(Exception e){
//Try to recover
}
finally{
try{
if(bis != null){
bis.close();
}
if(is != null){
is.close();
}
cursor.close();
projection = null;
}catch(Exception e){
}
}
}
Toast.makeText(this, " " + imagePath, Toast.LENGTH_SHORT).show();
到目前为止,我已经尝试了所有使用 imagePath 成员的方法,但这会导致抛出异常或其他错误。有什么建议吗?
【问题讨论】:
标签: android gridview path thumbnails