首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载图片并在ImageView中观看时“decode->decode returned”

下载图片并在ImageView中观看时“decode->decode returned”
EN

Stack Overflow用户
提问于 2012-02-16 13:27:53
回答 1查看 743关注 0票数 1

我尝试使用FlushedInputStream:Android decoder->decode returned false for Bitmap download

但是没有什么变化,因为我使用:BitmapFactory.decodeFile(path_of_my_downloaded_file),不使用BitmapFactory.decodeStream

这是我下载文件的代码:

代码语言:javascript
复制
  public static boolean downloadFile(String url, String dir, String name){
         Log.i("Start Downloading ", "=");
       //    Create download folder:
         File f = new File(dir);
         if(!f.exists()){
             f.mkdirs();
         }
        try {
            File fTo = new File(dir, name);
            URL downloadUrl = new URL(url);
            //create the new connection
            HttpURLConnection urlConnection = (HttpURLConnection) downloadUrl.openConnection();
            //set up some things on the connection
            urlConnection.setRequestMethod("GET");
            urlConnection.setDoOutput(true);
            //and connect!
            urlConnection.connect();
            FlushedInputStream in = new FlushedInputStream(downloadUrl.openStream());

//          in = new FlushedInputStream(in);

            byte[] buffer= new byte[4096];
//          Write file to toFolder
            FileOutputStream os = new FileOutputStream(fTo);
            try {
                 do{
                     int numread = in.read(buffer);  
                     if (numread <= 0)  {
                         break;
                     } 
                     os.write(buffer, 0, numread);
                }while(true);
            } catch (ConnectTimeoutException e) {
                e.printStackTrace();
                return false;

            }
            if (os != null) {
                os.close();
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            Log.e("Error reading file", e.toString());
            return false;
        }
        return true;
     }

下面是我将位图设置为ImageView的代码:

代码语言:javascript
复制
Bitmap bitmap = BitmapFactory.decodeFile(my_file);
mImageView.setImageBitmap(bitmap);

我一直都有"decoder->decode returned false"

注意:我必须先下载这个镜像。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-18 12:47:40

这就是形象的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9306034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档