我使用以下代码从常规图像网址获取图像:
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
我应该如何修改我的代码?
我建议你看看这个库:http://jsoup.org/
这似乎是页面重定向时的解决方案:http://blog.kosev.net/2011/01/follow-302-redirects-with.html