Пример #1
0
 @Override
 protected Bitmap doInBackground(String... strings) {
   String url = strings[0];
   Bitmap bm = null;
   try {
     URL aURL = new URL(url);
     URLConnection conn = aURL.openConnection();
     conn.connect();
     InputStream is = conn.getInputStream();
     int totalLen = conn.getContentLength();
     InputStreamWrapper bis = new InputStreamWrapper(is, 8192, totalLen);
     bis.setProgressListener(
         new InputStreamWrapper.InputStreamProgressListener() {
           @Override
           public void onProgress(float progressValue, long bytesLoaded, long bytesTotal) {
             publishProgress((int) (progressValue * 100));
           }
         });
     bm = BitmapFactory.decodeStream(bis);
     bis.close();
     is.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return bm;
 }
 @Override
 protected Bitmap doInBackground(String... strings) {
   String path = strings[0];
   Bitmap bm = null;
   try {
     File file = new File(path);
     FileInputStream fis = new FileInputStream(file);
     InputStreamWrapper bis = new InputStreamWrapper(fis, 8192, file.length());
     bis.setProgressListener(
         new InputStreamProgressListener() {
           public void onProgress(float progressValue, long bytesLoaded, long bytesTotal) {
             publishProgress((int) (progressValue * 100));
           }
         });
     bm = BitmapFactory.decodeStream(bis);
     bis.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return bm;
 }