title: How to apply this code in AsyncTask in Android?
body: <p>I have a code that decodes an image from a filepath, however, it takes up too much space and processing in the main thread. I have no idea how to adapt this into an AsyncTask class.</p>
  
  <pre><code>Bitmap bitmap;
  BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
  SetBitmapOptions(bitmapOptions);
  bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions);
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] byte_arr = stream.toByteArray();
  image_str = Base64.encodeToString(byte_arr, Base64.DEFAULT);
  viewImage.setImageBitmap(bitmap);
  </code></pre>
  
  <p>I wanted to use the code found here in Android Developer</p>
  
  <p><a href="http://developer.android.com/training/displaying-bitmaps/process-bitmap.html" rel="nofollow">http://developer.android.com/training/displaying-bitmaps/process-bitmap.html</a></p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>class BitmapWorkerTask extends AsyncTask&lt;Integer, Void, Bitmap&gt; {
      private final WeakReference&lt;ImageView&gt; imageViewReference;
      private int data = 0;
  
  public BitmapWorkerTask(ImageView imageView) {
      // Use a WeakReference to ensure the ImageView can be garbage collected
      imageViewReference = new WeakReference&lt;ImageView&gt;(imageView);
  }
  
  // Decode image in background.
  @Override
  protected Bitmap doInBackground(Integer... params) {
      data = params[0];
      return decodeSampledBitmapFromResource(getResources(), data, 100, 100));
  }
  
  // Once complete, see if ImageView is still around and set bitmap.
  @Override
  protected void onPostExecute(Bitmap bitmap) {
      if (imageViewReference != null &amp;&amp; bitmap != null) {
          final ImageView imageView = imageViewReference.get();
          if (imageView != null) {
              imageView.setImageBitmap(bitmap);
          }
      }
  }
  }
  </code></pre>
  
  <p>I have no idea what <code>resId</code> is and how to pass my bitmap variable to it</p>