gpt4 book ai didi

Android BitmapFactory.decodeStream(...) 不在模拟器上加载 HTTPS URL

转载 作者:太空狗 更新时间:2023-10-29 15:55:36 31 4
gpt4 key购买 nike

应用程序在模拟器上运行时不会从 HTTPS URL 加载图像。

示例代码:

URL url = new URL("https://someserver.com/photo.jpg");
mImageView.setImageBitmap(BitmapFactory.decodeStream(url.openStream()));

图像在实际设备上运行时加载得很好。如果通过 HTTP 而不是 HTTPS 访问图像,模拟器也会加载图像。

我是做错了什么还是这是一个已知问题?

最佳答案

使用以下代码在 imageview 中显示来自 url 的图像。

ImageView mImageView = (ImageView)findViewById(R.id.mImageView1);

URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
mImageView.setImageDrawable(d);

也可以使用下面的代码。

try {
URL url = new URL(imageUrl);
HttpGet httpRequest = null;

httpRequest = new HttpGet(url.toURI());

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

HttpEntity entity = response.getEntity();
BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
InputStream input = b_entity.getContent();

Bitmap bitmap = BitmapFactory.decodeStream(input);

ImageView mImageView = (ImageView) findViewById(R.id.mImageView);
mImageView.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
Log.e("log", "bad url", t);
} catch (IOException e) {
Log.e("log", "io error", t);
}

关于Android BitmapFactory.decodeStream(...) 不在模拟器上加载 HTTPS URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11372831/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com