1 package com.bumptech.glide.load.resource.transcode; 2 3 import android.content.Context; 4 import android.content.res.Resources; 5 import android.graphics.Bitmap; 6 7 import com.bumptech.glide.Glide; 8 import com.bumptech.glide.load.engine.Resource; 9 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 10 import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable; 11 import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawableResource; 12 13 /** 14 * An {@link com.bumptech.glide.load.resource.transcode.ResourceTranscoder} that converts 15 * {@link android.graphics.Bitmap}s into {@link android.graphics.drawable.BitmapDrawable}s. 16 */ 17 public class GlideBitmapDrawableTranscoder implements ResourceTranscoder<Bitmap, GlideBitmapDrawable> { 18 private final Resources resources; 19 private final BitmapPool bitmapPool; 20 21 public GlideBitmapDrawableTranscoder(Context context) { 22 this(context.getResources(), Glide.get(context).getBitmapPool()); 23 } 24 25 public GlideBitmapDrawableTranscoder(Resources resources, BitmapPool bitmapPool) { 26 this.resources = resources; 27 this.bitmapPool = bitmapPool; 28 } 29 30 @Override 31 public Resource<GlideBitmapDrawable> transcode(Resource<Bitmap> toTranscode) { 32 GlideBitmapDrawable drawable = new GlideBitmapDrawable(resources, toTranscode.get()); 33 return new GlideBitmapDrawableResource(drawable, bitmapPool); 34 } 35 36 @Override 37 public String getId() { 38 return "GlideBitmapDrawableTranscoder.com.bumptech.glide.load.resource.transcode"; 39 } 40 } 41