【问题标题】:How use HTTP post and get to retrieve images?如何使用 HTTP post 和 get 检索图像?
【发布时间】:2011-07-19 19:44:37
【问题描述】:

我想使用 HTTP post 和 get 方法来检索画廊视图的图像。 我该怎么做呢?

【问题讨论】:

    标签: android


    【解决方案1】:

    在这里搜索如何使用 HttpGet - 有很多示例。但是一旦你有一个有效的响应,你将需要使用 BitmapFactory.decodeStream 来获取一个位图(类似于下面的示例代码),你可以将其绘制到 ImageView 中。

    HttpResponse response = HttpClient.execute(request);
    HttpEntity entity     = response.getEntity();
    StatusLine statusLine = response.getStatusLine();
    int statusCode        = statusLine.getStatusCode();
    
    if (statusCode == HttpStatus.SC_OK)
    {
        InputStream inputStream = entity.getContent();
        Bitmap rawBitmap = null;
    
        BitmapFactory.Options bitmapOpt = new BitmapFactory.Options();
        bitmapOpt.inDither          = true;
        bitmapOpt.inPurgeable       = true;
        bitmapOpt.inInputShareable  = true;
        bitmapOpt.inTempStorage     = null;
        rawBitmap = BitmapFactory.decodeStream(inputStream, null, bitmapOpt);
    }
    

    【讨论】:

    • 谢谢!我想做的是每周将新图像上传到应用程序。您认为有更好的方法吗?
    • 还有一个使用 BufferedInputStream 和 BitmapFactory.decodeByteArray 的方法在stackoverflow.com/questions/2183808/… 中描述。但是我不确定“每周将新图像上传到应用程序”是什么意思?图像以哪种方式流动?
    • 所以说这周有一张……例如一棵树的图片……下周我希望这张图片变成一朵花。我只是希望能够每周更改这些图像。无需升级整个应用程序以更改图像的 URL。\
    • 所以是的...最好的方法是定期(每周)检查一个网站,然后使用其中一种方法。
    • 所以你说我必须每周升级应用程序?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 2011-02-25
    • 2011-07-22
    相关资源
    最近更新 更多