title: Android Glide load picture file apply overlay and set to imageview
body: <p>I have image files(png/jpg). When loading to listview, some of them I need to overlay with another transparent image. I do this using something like the following:</p>
  
  <pre><code>public Bitmap applyOverlay(Context context, Bitmap sourceImage, int overlayDrawableResourceId){
          Bitmap bitmap = null;
          try{
              int width = sourceImage.getWidth();
              int height = sourceImage.getHeight();
              Resources r = context.getResources();
              Drawable imageAsDrawable = new BitmapDrawable(r, sourceImage);
              Drawable[] layers = new Drawable[2];
              layers[0] = imageAsDrawable;
              layers[1] = new BitmapDrawable(r, BitmapUtils.decodeSampledBitmapFromResource(r, overlayDrawableResourceId, width, height));
              LayerDrawable layerDrawable = new LayerDrawable(layers);            
              bitmap = BitmapUtils.drawableToBitmap(layerDrawable);
          }catch (Exception ex){}
          return bitmap;
      }
  </code></pre>
  
  <p>where BitmapUtils is a custom class that implements bitmap-wise methods.</p>
  
  <pre><code>import android.content.Context;
  import android.content.res.Resources;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Canvas;
  import android.graphics.drawable.BitmapDrawable;
  import android.graphics.drawable.Drawable;
  import android.graphics.drawable.LayerDrawable;
  import android.media.ThumbnailUtils;
  import android.widget.ImageView;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  
  public class BitmapUtils {
  
      public static Bitmap applyOverlay(Context context, Bitmap sourceImage, int overlayDrawableResourceId){
          Bitmap bitmap = null;
          try{
              int width = sourceImage.getWidth();
              int height = sourceImage.getHeight();
              Resources r = context.getResources();
              Drawable imageAsDrawable = new BitmapDrawable(r, sourceImage);
              Drawable[] layers = new Drawable[2];
              layers[0] = imageAsDrawable;
              layers[1] = new BitmapDrawable(r, BitmapUtils.decodeSampledBitmapFromResource(r, overlayDrawableResourceId, width, height));
              LayerDrawable layerDrawable = new LayerDrawable(layers);
              bitmap = BitmapUtils.drawableToBitmap(layerDrawable);
          }catch (Exception ex){}
          return bitmap;
      }
  
      public static Bitmap drawableToBitmap(Drawable drawable) {
          Bitmap bitmap = null;
  
          if (drawable instanceof BitmapDrawable) {
              BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
              if(bitmapDrawable.getBitmap() != null) {
                  return bitmapDrawable.getBitmap();
              }
          }
  
          if(drawable.getIntrinsicWidth() &lt;= 0 || drawable.getIntrinsicHeight() &lt;= 0) {
              bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
          } else {
              bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
          }
  
          Canvas canvas = new Canvas(bitmap);
          drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
          drawable.draw(canvas);
          return bitmap;
      }
  
      static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight){
          // First decode with inJustDecodeBounds=true to check dimensions
          final BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeResource(res, resId, options);
  
          // Compute inSampleSize
          options.inSampleSize = computeInSampleSize(options, reqWidth, reqHeight);
  
          // Decode bitmap with inSampleSize set
          options.inJustDecodeBounds = false;
          return BitmapFactory.decodeResource(res, resId, options);
      }
  }
  </code></pre>
  
  <p><br/><br/>Using Universal Image Loader library for Android(UIL), this effect is achieved by writing a custom ImageDecoder and applying it to the ImageLoaderConfiguration.
  <br/><br/>The question is, how can I do this using Glide?
  <br/> Thanks.</p>