I have a very simple question:
I want to be able to save an image from a URL as a resource (temporarily, so it is deleted when the application closes), so I can then use it as an image resource (for example by setImageResource(int resID));
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t use image as resource if its wasn’t compiled into your application. The only imaginable way would be to modify the .apk file installed on the device, and that is not possible.
But I think what you’re really asking: how can I set downloaded image to
ImageView(or similar) so it can be displayed.Your steps:
HTTPClientorURLConnection).BitmapFactory.decodeFile(File)to loadBitmapfrom file into memory. You can safely delete the file after this step. It’s no longer needed (unless you plan to re-use it later, of course).ImageView.setImageBitmap(Bitmap)to set just loadedBitmapobject toImageView.And don’t forget to call
Bitmap.recycle()when loadedBitmapobject is no longer needed.