【问题标题】:This image could not be downloaded in android. Why?此图像无法在 android 中下载。为什么?
【发布时间】:2012-11-17 05:26:10
【问题描述】:

我使用以下代码下载图像。除一张外,所有图片均可成功下载。此图像http://www.dailydealster.com/system/illustrations/18089/original/18089s.jpg 无法下载。任何人都会遇到这样的问题。调试时下载图像。但是在发布模式下,这张图片没有下载

try {
  ImageView i = (ImageView)findViewById(R.id.image);
  Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
  i.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

【问题讨论】:

  • 如果您发布错误代码,帮助会更容易:)
  • 可以用内置浏览器应用下载图片吗?
  • 是的..使用浏览器下载图像
  • 您是否在 Logcat 中遇到任何错误?
  • no..当我调试代码时,图像被下载。但是在发布模式下,它没有下载

标签: android


【解决方案1】:

这在过去对我有用。

i = Drawable.createFromStream(((InputStream) new URL(imageUrl).getContent()),"image_name.png")

【讨论】:

    【解决方案2】:

    我很想将您的检索代码分隔成这样:

        URL url = new URL(photoUrl);
        URLConnection ucon = url.openConnection();
        Bitmap bitmap = BitmapFactory.decodeStream(ucon.getInputStream());
    
        ImageView image = (ImageView) findViewById(R.id.image);
        image.setImageBitmap(bitmap);
    

    这样您就可以避免使用强制转换,使其成为一种更强大的方法,并可能解决您的问题。

    【讨论】:

    • 运行时位图的值为空
    【解决方案3】:

    我的猜测是您的图像太大而无法以这种方式下载。尝试下载较小的图像,如果可行,请查看this postthis one

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2022-01-20
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多