本文整理汇总了Java中com.bumptech.glide.load.Transformation类的典型用法代码示例。如果您正苦于以下问题:Java Transformation类的具体用法?Java Transformation怎么用?Java Transformation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transformation类属于com.bumptech.glide.load包,在下文中一共展示了Transformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransformation
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
<Z> Transformation<Z> getTransformation(Class<Z> resourceClass) {
Transformation<Z> result = (Transformation<Z>) transformations.get(resourceClass);
if (result == null) {
for (Entry<Class<?>, Transformation<?>> entry : transformations.entrySet()) {
if (entry.getKey().isAssignableFrom(resourceClass)) {
result = (Transformation<Z>) entry.getValue();
break;
}
}
}
if (result == null) {
if (transformations.isEmpty() && isTransformationRequired) {
throw new IllegalArgumentException(
"Missing transformation for " + resourceClass + ". If you wish to"
+ " ignore unknown resource types, use the optional transformation methods.");
} else {
return UnitTransformation.get();
}
}
return result;
}
示例2: testSetsTransformationAsFrameTransformation
import com.bumptech.glide.load.Transformation; //导入依赖的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));
}
示例3: transform
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
/**
* @see GlideOptions#transform(Class<T>, Transformation<T>)
*/
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
@NonNull Transformation<T> arg1) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
}
return this;
}
示例4: testEquals
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@Test
public void testEquals() throws NoSuchAlgorithmException {
doAnswer(new Util.WriteDigest("first")).when(wrapped)
.updateDiskCacheKey(isA(MessageDigest.class));
@SuppressWarnings("unchecked") Transformation<Bitmap> other = mock(Transformation.class);
doAnswer(new Util.WriteDigest("other")).when(other)
.updateDiskCacheKey(isA(MessageDigest.class));
keyTester
.addEquivalenceGroup(
transformation,
new GifDrawableTransformation(wrapped),
new GifDrawableTransformation(wrapped))
.addEquivalenceGroup(wrapped)
.addEquivalenceGroup(new GifDrawableTransformation(other))
.addRegressionTest(
new GifDrawableTransformation(wrapped),
"a7937b64b8caa58f03721bb6bacf5c78cb235febe0e70b1b84cd99541461a08e")
.test();
}
示例5: transform
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
private RequestOptions transform(
@NonNull Transformation<Bitmap> transformation, boolean isRequired) {
if (isAutoCloneEnabled) {
return clone().transform(transformation, isRequired);
}
DrawableTransformation drawableTransformation =
new DrawableTransformation(transformation, isRequired);
transform(Bitmap.class, transformation, isRequired);
transform(Drawable.class, drawableTransformation, isRequired);
// TODO: remove BitmapDrawable decoder and this transformation.
// Registering as BitmapDrawable is simply an optimization to avoid some iteration and
// isAssignableFrom checks when obtaining the transformation later on. It can be removed without
// affecting the functionality.
transform(BitmapDrawable.class, drawableTransformation.asBitmapDrawable(), isRequired);
transform(GifDrawable.class, new GifDrawableTransformation(transformation), isRequired);
return selfOrThrowIfLocked();
}
示例6: ResourceCacheKey
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
ResourceCacheKey(
ArrayPool arrayPool,
Key sourceKey,
Key signature,
int width,
int height,
Transformation<?> appliedTransformation,
Class<?> decodedResourceClass,
Options options) {
this.arrayPool = arrayPool;
this.sourceKey = sourceKey;
this.signature = signature;
this.width = width;
this.height = height;
this.transformation = appliedTransformation;
this.decodedResourceClass = decodedResourceClass;
this.options = options;
}
示例7: encodeTransformedToStream
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
private boolean encodeTransformedToStream(GifDrawable drawable, OutputStream os) {
Transformation<Bitmap> transformation = drawable.getFrameTransformation();
GifDecoder decoder = decodeHeaders(drawable.getBuffer());
AnimatedGifEncoder encoder = factory.buildEncoder();
if (!encoder.start(os)) {
return false;
}
for (int i = 0; i < decoder.getFrameCount(); i++) {
Bitmap currentFrame = decoder.getNextFrame();
Resource<Bitmap> transformedResource =
getTransformedFrame(currentFrame, transformation, drawable);
try {
if (!encoder.addFrame(transformedResource.get())) {
return false;
}
int currentFrameIndex = decoder.getCurrentFrameIndex();
int delay = decoder.getDelay(currentFrameIndex);
encoder.setDelay(delay);
decoder.advance();
} finally {
transformedResource.recycle();
}
}
return encoder.finish();
}
示例8: getTransformedFrame
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
private Resource<Bitmap> getTransformedFrame(Bitmap currentFrame,
Transformation<Bitmap> transformation, GifDrawable drawable) {
// TODO: what if current frame is null?
Resource<Bitmap> bitmapResource = factory.buildFrameResource(currentFrame, bitmapPool);
Resource<Bitmap> transformedResource =
transformation.transform(
context, bitmapResource, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
if (!bitmapResource.equals(transformedResource)) {
bitmapResource.recycle();
}
return transformedResource;
}
示例9: transforms
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@Override
@SafeVarargs
@SuppressWarnings("varargs")
@CheckResult
public final GlideOptions transforms(@NonNull Transformation<Bitmap>... arg0) {
return (GlideOptions) super.transforms(arg0);
}
示例10: decode
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
private GifDrawableResource decode(
ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser, Options options) {
long startTime = LogTime.getLogTime();
final GifHeader header = parser.parseHeader();
if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) {
// If we couldn't decode the GIF, we will end up with a frame count of 0.
return null;
}
Bitmap.Config config = options.get(GifOptions.DECODE_FORMAT) == DecodeFormat.PREFER_RGB_565
? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;
int sampleSize = getSampleSize(header, width, height);
GifDecoder gifDecoder = gifDecoderFactory.build(provider, header, byteBuffer, sampleSize);
gifDecoder.setDefaultBitmapConfig(config);
gifDecoder.advance();
Bitmap firstFrame = gifDecoder.getNextFrame();
if (firstFrame == null) {
return null;
}
Transformation<Bitmap> unitTransformation = UnitTransformation.get();
GifDrawable gifDrawable =
new GifDrawable(context, gifDecoder, unitTransformation, width, height, firstFrame);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime));
}
return new GifDrawableResource(gifDrawable);
}
示例11: transform
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@SuppressWarnings("WeakerAccess")
final RequestOptions transform(DownsampleStrategy downsampleStrategy,
Transformation<Bitmap> transformation) {
if (isAutoCloneEnabled) {
return clone().transform(downsampleStrategy, transformation);
}
downsample(downsampleStrategy);
return transform(transformation);
}
示例12: optionalTransform
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
/**
* @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
*/
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
@NonNull Transformation<T> arg1) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
}
return this;
}
示例13: optionalTransform
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
/**
* @see GlideOptions#optionalTransform(Transformation<Bitmap>)
*/
@CheckResult
public GlideRequest<TranscodeType> optionalTransform(@NonNull Transformation<Bitmap> arg0) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0);
}
return this;
}
示例14: updateDiskCacheKey_throwsException
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@Test
public void updateDiskCacheKey_throwsException() throws NoSuchAlgorithmException {
// If this test fails, update testEqualsAndHashcode to use KeyTester including regression tests.
EngineKey key = new EngineKey(
"id",
new ObjectKey("signature"),
100,
100,
Collections.<Class<?>, Transformation<?>>emptyMap(),
Object.class,
Object.class,
new Options());
expectedException.expect(UnsupportedOperationException.class);
key.updateDiskCacheKey(MessageDigest.getInstance("SHA-1"));
}
示例15: testReturnsCurrentTransformationInGetFrameTransformation
import com.bumptech.glide.load.Transformation; //导入依赖的package包/类
@Test
public void testReturnsCurrentTransformationInGetFrameTransformation() {
@SuppressWarnings("unchecked")
Transformation<Bitmap> newTransformation = mock(Transformation.class);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
drawable.setFrameTransformation(newTransformation, bitmap);
verify(frameLoader).setFrameTransformation(eq(newTransformation), eq(bitmap));
}