Android ImageView set to local URL not working?
So I am new to Android, but I do not understand why this does not work (and how to get it to work):
ImageView i = (ImageView) findViewById(R.id.image_to_display);
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
i.setImageURI(uri)
I did a Toast and have made sur开发者_如何转开发e that uri.toString() returns a url like content://...
I am also sure that i
is a valid reference, because I am successfully able to set it to local images that are part of the .apk
.
So why would this not work, and how can I get it to work?
Thanks
If you don't HAVE to have it be an Uri you could do something like this instead.
String fullpath = Environment.getExternalStorageDirectory() + "/pathtoyourfile"
// take the path create a bitmap and populate the ImageView with it.
ImageView iv = (ImageView) v.findViewById(R.id.thumbnail);
Bitmap bm = BitmapFactory.decodeFile(fullpath);
iv.setImageBitmap(bm);
Try loading it yourself and then passing it in:
ContentResolver cr = getContentResolver();
InputStream in = cr.openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(in);
if (bitmap != null) {
i.setImageBitmap(bitmap);
}
精彩评论