【发布时间】:2013-08-27 07:54:05
【问题描述】:
我尝试了几乎所有可能的方法来从存储的文件路径将图像设置为image-view。
它们都不起作用。 图像是从其他活动的图库中选择的,图像路径存储到数据库中。
图像的类型为 .jpg .jpeg .png
图像路径存储在数据库中,路径不带任何扩展名
eg. /external/storage/media/carimagename
当我尝试使用此代码将图像设置为 imageview 时,没有错误但未设置图像。
for(int i=0;i<n;i++)
{
Bitmap pic = BitmapFactory.decodeFile(listview_arraypro1[i]);
carpict.setImageBitmap(pic);
/// File imgFile =new File("listview_arraypro1[i]");
// carpict.setImageBitmap(BitmapFactory.decodeFile(imgFile.getAbsolutePath()));
// Bitmap carpic = BitmapFactory.decodeStream(is);
// carpic = Bitmap.createScaledBitmap(carpic, 72, 70, false);
}
如何将路径格式/external/storage/media/carimagename 的图像设置为imageview?
我正在使用以下内容获取上一个活动中的图像路径
Uri selectedImage = imageReturnedIntent.getData();
String selectedImagePath = selectedImage.getPath();
我是不是从 selectedImagePath 得到了错误的路径?
这是我使用这个没有 mnt/sdcard 的路径
private String getRealPathFromURI(Uri contentURI) {
Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
}
File imageFile = new File(getRealPathFromURI(selectedImage));
String path= imageFile.toString();
【问题讨论】:
标签: java android xml bitmap imageview