本文介绍了"德codeR->德code返回false"当下载图像,并查看它的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用FlushedInputStream:<一href=\"http://stackoverflow.com/questions/4339082/android-de$c$cr-de$c$c-returned-false-for-bitmap-download/5039288#5039288\">Android德codeR-&GT;德code返回位图下载

I try to use FlushedInputStream : Android decoder->decode returned false for Bitmap download

但没有什么改变,因为我使用: BitmapFactory.de codeFILE(path_of_my_downloaded_file)不使用 BitmapFactory.de codeStream

but nothing change, because i use: BitmapFactory.decodeFile(path_of_my_downloaded_file), not use BitmapFactory.decodeStream

这是下载文件我的code:

This is my code of download file:

  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;
     }

这是我的code设置位图ImageView的:

And this is my code to set Bitmap to ImageView:

Bitmap bitmap = BitmapFactory.decodeFile(my_file);
mImageView.setImageBitmap(bitmap);

我总是有去codeR-&GT;德code返回false

请注意:我必须先下载这个图片

Note: I have to download this image first.

推荐答案

这是形象的问题。

这篇关于&QUOT;德codeR-&GT;德code返回false&QUOT;当下载图像,并查看它的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 12:57