本文整理汇总了Java中com.bumptech.glide.load.resource.bitmap.BitmapResource类的典型用法代码示例。如果您正苦于以下问题:Java BitmapResource类的具体用法?Java BitmapResource怎么用?Java BitmapResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitmapResource类属于com.bumptech.glide.load.resource.bitmap包,在下文中一共展示了BitmapResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<GifDrawable> transform(
Context context, Resource<GifDrawable> resource, int outWidth, int outHeight) {
GifDrawable drawable = resource.get();
// The drawable needs to be initialized with the correct width and height in order for a view
// displaying it to end up with the right dimensions. Since our transformations may arbitrarily
// modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the
// transformation to see what the final transformed dimensions will be so that our drawable can
// report the correct intrinsic width and height.
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap firstFrame = drawable.getFirstFrame();
Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool);
Resource<Bitmap> transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight);
if (!bitmapResource.equals(transformed)) {
bitmapResource.recycle();
}
Bitmap transformedFrame = transformed.get();
drawable.setFrameTransformation(wrapped, transformedFrame);
return resource;
}
示例2: createScaledBitmapInto
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
throws BitmapDecodingException
{
final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model),
Glide.get(context).getBitmapPool(),
width, height,
DecodeFormat.PREFER_RGB_565);
final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool());
final Resource<Bitmap> result = new FitCenter(context).transform(resource, width, height);
if (result == null) {
throw new BitmapDecodingException("unable to transform Bitmap");
}
return result.get();
}
示例3: createScaledBitmapInto
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
private static <T> Bitmap createScaledBitmapInto(Context context, T model,
int width, int height)
throws BitmapDecodingException {
final Bitmap rough = Downsampler.AT_LEAST
.decode(getInputStreamForModel(context, model),
Glide.get(context).getBitmapPool(),
width, height, DecodeFormat.PREFER_RGB_565);
final Resource<Bitmap> resource = BitmapResource
.obtain(rough, Glide.get(context).getBitmapPool());
final Resource<Bitmap> result =
new FitCenter(context).transform(resource, width, height);
if (result == null) {
throw new BitmapDecodingException("unable to transform Bitmap");
}
return result.get();
}
示例4: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例5: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(source, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例6: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例7: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
Canvas canvas = new Canvas(result);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, sMaskingPaint);
return BitmapResource.obtain(result, mBitmapPool);
}
示例8: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例9: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
mWidth = (source.getWidth() - size) / 2;
mHeight = (source.getHeight() - size) / 2;
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例10: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例11: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.RGB_565);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例12: decodeGifWrapper
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
private ImageWrapper decodeGifWrapper(InputStream bis, int width, int height) throws IOException {
ImageWrapper result = null;
Resource<GifDrawable> gifResource = gifDecoder.decode(bis, width, height);
if (gifResource != null) {
GifDrawable drawable = gifResource.get();
// We can more efficiently hold Bitmaps in memory, so for static GIFs, try to return Bitmaps
// instead. Returning a Bitmap incurs the cost of allocating the GifDrawable as well as the normal
// Bitmap allocation, but since we can encode the Bitmap out as a JPEG, future decodes will be
// efficient.
if (drawable.getNumberOfFrames() > 1) {
result = new ImageWrapper(null /*bitmapResource*/, gifResource);
} else {
Resource<Bitmap> bitmapResource = new BitmapResource(drawable.getCurrentFrame(), bitmapPool);
result = new ImageWrapper(bitmapResource, null /*gifResource*/);
}
}
return result;
}
示例13: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
canvas.drawBitmap(source, 0, 0, mMaskingPaint);
canvas.drawColor(0x44000000);
return BitmapResource.obtain(result, mBitmapPool);
}
示例14: decode
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override public @Nullable Resource<Bitmap> decode(File file, int w, int h, Options options) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(w * h * 4);
FileInputStream stream = new FileInputStream(file);
try {
stream.getChannel().read(buffer);
} finally {
stream.close();
}
Bitmap result = Bitmap.createBitmap(w, h, Config.ARGB_8888);
try {
buffer.rewind();
result.copyPixelsFromBuffer(buffer);
return BitmapResource.obtain(result, pool);
} catch (RuntimeException ex) {
result.recycle();
throw ex;
}
}
示例15: transform
import com.bumptech.glide.load.resource.bitmap.BitmapResource; //导入依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}