尝试使用图像路径将图像设置为图像视图。
我的图片路径
String img_path ="/storage/sdcard0/Fbt/xylo.jpg";
图片路径代码
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.Media.DATA);
return cursor.getString(idx);
}
}
selectedImage = imageReturnedIntent.getData();
File imageFile = new File(getRealPathFromURI(selectedImage));
String path= imageFile.toString();
输出=/storage/sdcard0/Fbt/xylo.jpg
我尝试了所有可能的代码仍然没有成功
ImageView carpict =(ImageView)findViewById(R.id.img); Bitmap bitmap = BitmapFactory.decodeFile(img_path); carpict.setImageBitmap(bitmap);
2.
Uri image22 =(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+img_path));
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(image22);
Bitmap carpic = BitmapFactory.decodeStream(imageStream);
// carpic = Bitmap.createScaledBitmap(carpic, 72,72, false);
carpict.setImageBitmap(carpic);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
第三。
carpict.setImageURI
(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+img_path));
第四。
File imgFile =new File("img_path");
carpict.setImageBitmap(BitmapFactory.decodeFile(imgFile.getAbsolutePath()));
我还添加了
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
谁能告诉我哪里出错了?