use of com.bumptech.glide.load.resource.SimpleResource in project glide by bumptech.
the class SvgDrawableTranscoder method transcode.
@Override
public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) {
SVG svg = toTranscode.get();
Picture picture = svg.renderToPicture();
PictureDrawable drawable = new PictureDrawable(picture);
return new SimpleResource<PictureDrawable>(drawable);
}
use of com.bumptech.glide.load.resource.SimpleResource in project glide by bumptech.
the class DrawableTransformationTest method transform_withColorDrawable_andUnitBitmapTransformation_recycles.
@Test
public void transform_withColorDrawable_andUnitBitmapTransformation_recycles() {
bitmapPool = mock(BitmapPool.class);
Glide.tearDown();
Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
when(bitmapTransformation.transform(any(Context.class), anyBitmapResource(), anyInt(), anyInt())).thenAnswer(new ReturnGivenResource());
ColorDrawable colorDrawable = new ColorDrawable(Color.RED);
final Resource<Drawable> input = new SimpleResource<Drawable>(colorDrawable);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Bitmap bitmap = (Bitmap) invocationOnMock.getArguments()[0];
assertThat(bitmap.getWidth()).isEqualTo(100);
assertThat(bitmap.getHeight()).isEqualTo(200);
return null;
}
}).when(bitmapPool).put(any(Bitmap.class));
when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class))).thenAnswer(new Answer<Bitmap>() {
@Override
public Bitmap answer(InvocationOnMock invocationOnMock) throws Throwable {
int width = (Integer) invocationOnMock.getArguments()[0];
int height = (Integer) invocationOnMock.getArguments()[1];
Bitmap.Config config = (Bitmap.Config) invocationOnMock.getArguments()[2];
return Bitmap.createBitmap(width, height, config);
}
});
transformation.transform(context, input, /*outWidth=*/
100, /*outHeight=*/
200);
verify(bitmapPool).put(isA(Bitmap.class));
}
use of com.bumptech.glide.load.resource.SimpleResource in project android by nextcloud.
the class SvgDecoder method decode.
public Resource<SVG> decode(InputStream source, int w, int h) throws IOException {
try {
SVG svg = SVG.getFromInputStream(source);
if (width > 0) {
svg.setDocumentWidth(width);
}
if (height > 0) {
svg.setDocumentHeight(height);
}
svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
return new SimpleResource<>(svg);
} catch (SVGParseException ex) {
throw new IOException("Cannot load SVG from stream", ex);
}
}
use of com.bumptech.glide.load.resource.SimpleResource in project android by nextcloud.
the class SvgBitmapTranscoder method transcode.
@Override
public Resource<Bitmap> transcode(Resource<SVG> toTranscode) {
SVG svg = toTranscode.get();
try {
svg.setDocumentHeight("100%");
svg.setDocumentWidth("100%");
} catch (SVGParseException e) {
Log_OC.e(this, "Could not set document size. Output might have wrong size");
}
// Create a canvas to draw onto
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// Render our document onto our canvas
svg.renderToCanvas(canvas);
return new SimpleResource<>(bitmap);
}
use of com.bumptech.glide.load.resource.SimpleResource in project PocketHub by pockethub.
the class SvgDrawableTranscoder method transcode.
@Nullable
@Override
public Resource<Drawable> transcode(@NonNull Resource<SVG> toTranscode, @NonNull Options options) {
SVG svg = toTranscode.get();
float ratio = svg.getDocumentAspectRatio();
int width = svg.getDocumentWidth() > 0 ? (int) svg.getDocumentWidth() : 1024;
int height = (int) (svg.getDocumentHeight() > 0 ? svg.getDocumentHeight() : (width / ratio));
Picture picture = svg.renderToPicture(width, height);
PictureDrawable drawable = new PictureDrawable(picture);
return new SimpleResource<>(drawable);
}
Aggregations