提交 114a12ea 编写于 作者: S Sam Judd

Add a Bitmap -> GlideDrawable transcoder.

上级 162c0ca8
package com.bumptech.glide.load.resource.transcode;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
/**
* A wrapper for {@link com.bumptech.glide.load.resource.transcode.GlideBitmapDrawableTranscoder} that transcodes
* to {@link com.bumptech.glide.load.resource.drawable.GlideDrawable} rather than
* {@link com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable}.
*
* TODO: use ? extends GlideDrawable rather than GlideDrawable directly and remove this class.
*/
public class BitmapToGlideDrawableTranscoder implements ResourceTranscoder<Bitmap, GlideDrawable> {
private final GlideBitmapDrawableTranscoder glideBitmapDrawableTranscoder;
public BitmapToGlideDrawableTranscoder(Context context) {
this(new GlideBitmapDrawableTranscoder(context));
}
public BitmapToGlideDrawableTranscoder(GlideBitmapDrawableTranscoder glideBitmapDrawableTranscoder) {
this.glideBitmapDrawableTranscoder = glideBitmapDrawableTranscoder;
}
@SuppressWarnings("unchecked")
@Override
public Resource<GlideDrawable> transcode(Resource<Bitmap> toTranscode) {
return (Resource<GlideDrawable>) (Resource<? extends GlideDrawable>)
glideBitmapDrawableTranscoder.transcode(toTranscode);
}
@Override
public String getId() {
return glideBitmapDrawableTranscoder.getId();
}
}
package com.bumptech.glide.load.resource.transcode;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
......@@ -15,6 +17,10 @@ public class GlideBitmapDrawableTranscoder implements ResourceTranscoder<Bitmap,
private final Resources resources;
private final BitmapPool bitmapPool;
public GlideBitmapDrawableTranscoder(Context context) {
this(context.getResources(), Glide.get(context).getBitmapPool());
}
public GlideBitmapDrawableTranscoder(Resources resources, BitmapPool bitmapPool) {
this.resources = resources;
this.bitmapPool = bitmapPool;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册