1

我已将图像从 url 下载到 sd 卡。它在 sd 卡中显示为普通缩略图,但是当我单击它查看它时,Could not load image还会显示一条消息,该图像在 imageview 中不显示。该图像是在 Async Task 的帮助下下载的。现在我想先检查图像是否可显示。如果没有删除它并重新下载它。

下载图片的代码:

      protected Void doInBackground(String... params) {
      try{
      String fileName = params[0].substring(params[0].lastIndexOf('/') + 1);
  URL url = new URL(params[0]);
  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  urlConnection.setRequestMethod("GET");
  urlConnection.setDoOutput(true);                   
  urlConnection.connect();   

  File file = new File(SwipeActivity.filename,fileName);

  FileOutputStream fileOutput = new FileOutputStream(file);
  InputStream inputStream = urlConnection.getInputStream(); 
  byte[] buffer = new byte[1024];
  int bufferLength = 0;
  while ( (bufferLength = inputStream.read(buffer)) > 0 ) 
  {                 
    fileOutput.write(buffer, 0, bufferLength);                
  }             
  fileOutput.close(); 
    }
    catch (Exception e) {
        // TODO: handle exception
    }
    return null;
}

提前感谢任何帮助。

4

1 回答 1

0

您可以尝试检查图像是否可在 Gallery 应用程序中显示。我似乎在使用普通的 PNG 图像时遇到了这个问题,诀窍是它不是 RGB 图片,而是 CMYK 颜色格式。输出与您的相似,android 不会直接显示 CMYK 图像

于 2013-10-14T08:15:14.030 回答