如何在Android中从HTML页面获取图像

问题描述 投票:0回答:2

我使用以下代码从常规图像网址获取图像:

try
{
  url = new URL("http://example.com/test.jpg");
  final Bitmap bmp = BitmapFactory.decodeStream(url.openConnection()
                    .getInputStream());
  final ImageView imageView = (ImageView) findViewById(R.id.imageView2);
  MainActivity.this.runOnUiThread(new Runnable()
  {
    @Override
    public void run()
    {
      imageView.setImageBitmap(bmp);
    }
  });
}
catch (Exception e)
{
  e.printStackTrace(); 
}

但是,我想下载由html或php页面显示的图像。

  url = new URL("http://example.com/showimage.php");

如果我使用它,我会收到以下消息:

SkImageDecoder::Factory 返回 null

我应该如何修改我的代码?

android image-loading
2个回答
1
投票

我建议你看看这个库:http://jsoup.org/


0
投票

这似乎是页面重定向时的解决方案:http://blog.kosev.net/2011/01/follow-302-redirects-with.html

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.