本文整理匯總了Java中com.bumptech.glide.load.engine.Resource類的典型用法代碼示例。如果您正苦於以下問題:Java Resource類的具體用法?Java Resource怎麽用?Java Resource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Resource類屬於com.bumptech.glide.load.engine包,在下文中一共展示了Resource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transform
import com.bumptech.glide.load.engine.Resource; //導入依賴的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);
}
示例2: testPassesGivenArgumentsToTransform
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testPassesGivenArgumentsToTransform() {
final int expectedWidth = 13;
final int expectedHeight = 148;
final Resource<Bitmap> resource = mockResource(223, 4123);
BitmapTransformation transformation = new BitmapTransformation() {
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) { }
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform,
int outWidth, int outHeight) {
assertEquals(bitmapPool, pool);
assertEquals(resource.get(), toTransform);
assertEquals(expectedWidth, outWidth);
assertEquals(expectedHeight, outHeight);
return resource.get();
}
};
transformation.transform(context, resource, expectedWidth, expectedHeight);
}
示例3: transform
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Override
public final Resource<Bitmap> transform(
Context context, Resource<Bitmap> resource, int outWidth, int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
示例4: testSetsTransformationAsFrameTransformation
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testSetsTransformationAsFrameTransformation() {
Resource<GifDrawable> resource = mockResource();
GifDrawable gifDrawable = mock(GifDrawable.class);
Transformation<Bitmap> unitTransformation = UnitTransformation.get();
when(gifDrawable.getFrameTransformation()).thenReturn(unitTransformation);
when(gifDrawable.getIntrinsicWidth()).thenReturn(500);
when(gifDrawable.getIntrinsicHeight()).thenReturn(500);
when(resource.get()).thenReturn(gifDrawable);
Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(gifDrawable.getFirstFrame()).thenReturn(firstFrame);
final int width = 123;
final int height = 456;
Bitmap expectedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Resource<Bitmap> expectedResource = mockResource();
when(expectedResource.get()).thenReturn(expectedBitmap);
when(wrapped.transform(any(Context.class), Util.<Bitmap>anyResource(), anyInt(), anyInt()))
.thenReturn(expectedResource);
transformation.transform(context, resource, width, height);
verify(gifDrawable).setFrameTransformation(isA(Transformation.class), eq(expectedBitmap));
}
示例5: decodeGifWrapper
import com.bumptech.glide.load.engine.Resource; //導入依賴的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;
}
示例6: transform
import com.bumptech.glide.load.engine.Resource; //導入依賴的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);
}
示例7: createScaledBitmapInto
import com.bumptech.glide.load.engine.Resource; //導入依賴的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();
}
示例8: testProvidesBitmapFromGivenResourceToWrappedTransformation
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testProvidesBitmapFromGivenResourceToWrappedTransformation() {
int outWidth = 332;
int outHeight = 111;
Resource<Bitmap> transformed = Util.mockResource();
when(transformed.get())
.thenReturn(Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888));
when(wrapped.transform(anyContext(), Util.<Bitmap>anyResource(), anyInt(), anyInt()))
.thenReturn(transformed);
transformation.transform(context, drawableResourceToTransform, outWidth, outHeight);
ArgumentCaptor<Resource<Bitmap>> captor = Util.cast(ArgumentCaptor.forClass(Resource.class));
verify(wrapped).transform(anyContext(), captor.capture(), eq(outWidth), eq(outHeight));
assertThat(captor.getValue().get()).isEqualTo(bitmapToTransform);
}
示例9: testReturnsGivenResourceWhenBitmapNotTransformed
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testReturnsGivenResourceWhenBitmapNotTransformed() {
BitmapTransformation transformation = new BitmapTransformation() {
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) { }
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform,
int outWidth, int outHeight) {
return toTransform;
}
};
Resource<Bitmap> resource = mockResource(100, 100);
assertEquals(resource, transformation.transform(context, resource, 1, 1));
}
示例10: transform_withBitmapDrawable_andUnitBitmapTransformation_doesNotRecycle
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void transform_withBitmapDrawable_andUnitBitmapTransformation_doesNotRecycle() {
when(
bitmapTransformation
.transform(
any(Context.class), anyBitmapResource(), anyInt(), anyInt()))
.thenAnswer(new ReturnGivenResource());
Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
@SuppressWarnings("unchecked")
Resource<Drawable> input =
(Resource<Drawable>) (Resource<?>) new BitmapDrawableResource(drawable, bitmapPool);
transformation.transform(context, input, /*outWidth=*/ 100, /*outHeight=*/ 200);
assertThat(bitmap.isRecycled()).isFalse();
}
示例11: testReturnsNewResourceWhenBitmapTransformed
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testReturnsNewResourceWhenBitmapTransformed() {
final Bitmap transformed = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444);
BitmapTransformation transformation = new BitmapTransformation() {
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) { }
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap bitmap, int outWidth,
int outHeight) {
return transformed;
}
};
Resource<Bitmap> resource = mockResource(1, 2);
assertNotSame(resource, transformation.transform(context, resource, 100, 100));
}
示例12: createScaledBitmapInto
import com.bumptech.glide.load.engine.Resource; //導入依賴的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();
}
示例13: testReturnsNewResourceIfTransformationDoesTransform
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testReturnsNewResourceIfTransformationDoesTransform() {
int outWidth = 999;
int outHeight = 555;
Bitmap transformedBitmap = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.RGB_565);
Resource<Bitmap> transformedBitmapResource = Util.mockResource();
when(transformedBitmapResource.get()).thenReturn(transformedBitmap);
when(wrapped.transform(anyContext(), Util.<Bitmap>anyResource(), eq(outWidth), eq(outHeight)))
.thenReturn(transformedBitmapResource);
Resource<BitmapDrawable> transformed =
transformation.transform(context, drawableResourceToTransform, outWidth, outHeight);
assertThat(transformed.get().getBitmap()).isEqualTo(transformedBitmap);
}
示例14: testReturnsNullIfTransformReturnsNull
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testReturnsNullIfTransformReturnsNull() {
BitmapTransformation transform = new BitmapTransformation() {
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) { }
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform,
int outWidth, int outHeight) {
return null;
}
};
Resource<Bitmap> resource = mockResource(100, 100);
assertNull(transform.transform(context, resource, 100, 100));
}
示例15: testSizeIsBasedOnResource
import com.bumptech.glide.load.engine.Resource; //導入依賴的package包/類
@Test
public void testSizeIsBasedOnResource() {
LruResourceCache resourceCache = new LruResourceCache(100);
Resource<?> first = getResource(50);
MockKey firstKey = new MockKey();
resourceCache.put(firstKey, first);
Resource<?> second = getResource(50);
MockKey secondKey = new MockKey();
resourceCache.put(secondKey, second);
assertTrue(resourceCache.contains(firstKey));
assertTrue(resourceCache.contains(secondKey));
Resource<?> third = getResource(50);
MockKey thirdKey = new MockKey();
resourceCache.put(thirdKey, third);
assertFalse(resourceCache.contains(firstKey));
assertTrue(resourceCache.contains(secondKey));
assertTrue(resourceCache.contains(thirdKey));
}