How to load an ImageView from a png file?

拥有回忆 提交于 2019-11-30 05:04:33

Try BitmapFactory.decodeFile() and then setImageBitmap() on the ImageView.

Apc

Also possible:

java.io.FileInputStream in = openFileInput("myfile.png");
iv.setImageBitmap(BitmapFactory.decodeStream(in));
user2107276
iv.setImageURI(Uri.fromFile(in));

Why not this way:

ImageView MyImageView = (ImageView)findViewById(R.id.imageView1);
Drawable d = Drawable.createFromPath( PATH TO FILE );
MyImageView.setImageDrawable(d);
Nauman Khalid
bitmap = BitmapFactory.decodeFile(imageInSD);
Alvaro

There should be no difference between decodeStream() and decodeFile(). decodeFile() method opens an inputstream and calls decodeStream(). This was already answered at this link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!