Can you help me please? I've tried :
ImageButton imgbt=(ImageButton)findViewById(R.id.imgbutton);
Uri imgUri=Uri.parse("/data/data/MYFOLDER/myimage.png");
imgbt.setImageUri(imgUri);
but I didn't see anything, simply a void button.
ImageView. setImageUri only works for local Uri, ie a reference to a local disk file, not a URL to an image on the network. Here is an example of how to fetch a Bitmap from the network.
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.
ImageView.setImageUri only works for local Uri, ie a reference to a local disk file, not a URL to an image on the network.
Here is an example of how to fetch a Bitmap from the network.
private Bitmap getImageBitmap(String url) {
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e(TAG, "Error getting bitmap", e);
}
return bm;
}
Once you have the Bitmap from getImageBitmap(), use: imgView.setImageBitmap(bm);
It should be
Uri imgUri=Uri.parse("file:///data/data/MYFOLDER/myimage.png");
How about this one:
Bitmap bitmap = BitmapFactory.decodeFile(fullFileName);
imgProfileImage.setImageBitmap(bitmap);
Its best to avoid building the path by hand, try :
imgbt.setImageUri(Uri.fromFile(new File("/data/data/....")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With