How to load an ImageView with a png file without using "setImageBitmap()"?

Viewed 2185

I do some processing (quality improvement and a bit of resizing) on a Bitmap object and then store it using bitmap.compress() function by giving a file name "myfile.png".

newbitmap = processImage(bitmap);
FileOutputStream fos = context.openFileOutput("myfile.png", Context.MODE_PRIVATE);
newbitmap.compress(CompressFormat.PNG, 100, fos);

Now I want to load this image in an ImageView but I cant use setImageBitmap() to do that. Is there any alternative ?

The reason I cant use setImageBitmap() is that I am using RemoteViews for a widget, and using bitmap method leads to Failed Binder Transaction error when the image is large.

I tried to set image uri using the code below but the image does not load on the ImageView:

RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

File internalFile = context.getFileStreamPath("myfile.png");
Uri internal = Uri.fromFile(internalFile);
rv.setImageViewUri(R.id.widgetImageView, internal);
updateAppWidget(awID, rv);

Thanks for your help!

2 Answers
Related