use of com.bumptech.glide.load.resource.SimpleResource in project glide by bumptech.
the class SvgDrawableTranscoder method transcode.
@Nullable
@Override
public Resource<PictureDrawable> transcode(@NonNull Resource<SVG> toTranscode, @NonNull Options options) {
SVG svg = toTranscode.get();
Picture picture = svg.renderToPicture();
PictureDrawable drawable = new PictureDrawable(picture);
return new SimpleResource<>(drawable);
}
use of com.bumptech.glide.load.resource.SimpleResource in project android by nextcloud.
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 android by nextcloud.
the class SvgOrImageDecoder method decode.
public Resource<SVGorImage> decode(InputStream source, int w, int h) throws IOException {
byte[] array = new byte[source.available()];
source.read(array);
ByteArrayInputStream svgInputStream = new ByteArrayInputStream(array.clone());
ByteArrayInputStream pngInputStream = new ByteArrayInputStream(array.clone());
try {
SVG svg = SVG.getFromInputStream(svgInputStream);
source.close();
pngInputStream.close();
if (width > 0) {
svg.setDocumentWidth(width);
}
if (height > 0) {
svg.setDocumentHeight(height);
}
svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
return new SimpleResource<>(new SVGorImage(svg, null));
} catch (SVGParseException ex) {
Bitmap bitmap = BitmapFactory.decodeStream(pngInputStream);
return new SimpleResource<>(new SVGorImage(null, bitmap));
}
}
use of com.bumptech.glide.load.resource.SimpleResource in project android by nextcloud.
the class SvgOrImageBitmapTranscoder method transcode.
@Override
public Resource<Bitmap> transcode(Resource<SVGorImage> toTranscode) {
SVGorImage svGorImage = toTranscode.get();
if (svGorImage.getSVG() != null) {
SVG svg = svGorImage.getSVG();
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);
} else {
Bitmap bitmap = svGorImage.getBitmap();
return new SimpleResource<>(bitmap);
}
}
Aggregations