Search in sources :

Example 16 with SVG

use of com.caverock.androidsvg.SVG 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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) SVG(com.caverock.androidsvg.SVG) SVGParseException(com.caverock.androidsvg.SVGParseException) Canvas(android.graphics.Canvas) SimpleResource(com.bumptech.glide.load.resource.SimpleResource)

Aggregations

SVG (com.caverock.androidsvg.SVG)16 PictureDrawable (android.graphics.drawable.PictureDrawable)8 SimpleResource (com.bumptech.glide.load.resource.SimpleResource)8 SVGParseException (com.caverock.androidsvg.SVGParseException)7 Bitmap (android.graphics.Bitmap)6 Canvas (android.graphics.Canvas)5 Uri (android.net.Uri)5 StreamEncoder (com.bumptech.glide.load.model.StreamEncoder)5 SvgDecoder (com.owncloud.android.utils.svg.SvgDecoder)5 InputStream (java.io.InputStream)5 Picture (android.graphics.Picture)4 SvgDrawableTranscoder (com.owncloud.android.utils.svg.SvgDrawableTranscoder)4 FileToStreamDecoder (com.bumptech.glide.load.resource.file.FileToStreamDecoder)2 BitmapShader (android.graphics.BitmapShader)1 Matrix (android.graphics.Matrix)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 Nullable (android.support.annotation.Nullable)1 Nullable (androidx.annotation.Nullable)1 CustomGlideUriLoader (com.owncloud.android.utils.glide.CustomGlideUriLoader)1