【问题标题】:How to get a picture from url site and store it to device? [duplicate]如何从 url 站点获取图片并将其存储到设备? [复制]
【发布时间】:2012-08-06 07:07:05
【问题描述】:

可能重复:
Android: How to store images from url & save it in SD card

我从 web 解析一个 xml 文件

它有一个像这样的图片网址:http://xxxxxx.jpg

然后我用一个

私有字符串 url_picture = "http://xxxxx.jpg";

我想将图片存储到设备中

我该怎么办?

【问题讨论】:

    标签: android


    【解决方案1】:

    我编写了这段代码来接收来自 url 的图像。如果您查看此链接,它会告诉您如何将其保存在 sd 卡上 Store Bitmap image to SD Card in Android

    private Bitmap getBitmap(String str, Options options) {
        // TODO Auto-generated method stub
        Bitmap bm = null;
        InputStream inStream = null;
        try {
            inStream = HttpConnection(str);
            bm = BitmapFactory.decodeStream(inStream, null, options);
            inStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return bm;
    }
    

    【讨论】:

    • 我应该向方法传递什么样的选项?
    • 我把url转bitmap了,但是压缩到文件失败发现bitmap的宽高都是-1怎么办?
    猜你喜欢
    • 1970-01-01
    • 2019-10-21
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 2016-10-19
    • 2015-06-19
    • 2014-03-01
    相关资源
    最近更新 更多