保存图像从InputStream中检索本地 [英] Saving Image Retrieved from InputStream locally

查看:169
本文介绍了保存图像从InputStream中检索本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code从URL检索图像和活动上进行展示。

I used the following code to retrieve an image from a url and display it within an activity.

    InputStream is = (InputStream) new URL(url[0]).getContent();
    Drawable d = Drawable.createFromStream(is, "imagename");
    ImageView... 

现在我想要保存此图像(可绘制D)在本地当用户点击一个按钮,这样我就可以在另一个活动再次显示(与其他几个任务一起)。

Now I want to save this image (Drawable d) locally when a user clicks a button so I can display it again in another activity (along with a few other tasks).

我想它存储在app文件夹本身,而不是在SD卡上。

I'd like to store it within the app folder itself rather than on the SD card.

我将如何做到这一点?

谢谢!
香农

推荐答案

这会为你做它:

Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
FileOutputStream out = openFileOutput(filename, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);

这篇关于保存图像从InputStream中检索本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆