Search in sources :

Example 6 with SimpleResource

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);
}
Also used : SVG(com.caverock.androidsvg.SVG) Picture(android.graphics.Picture) PictureDrawable(android.graphics.drawable.PictureDrawable) SimpleResource(com.bumptech.glide.load.resource.SimpleResource) Nullable(android.support.annotation.Nullable)

Example 7 with SimpleResource

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);
}
Also used : SVG(com.caverock.androidsvg.SVG) Picture(android.graphics.Picture) PictureDrawable(android.graphics.drawable.PictureDrawable) SimpleResource(com.bumptech.glide.load.resource.SimpleResource)

Example 8 with SimpleResource

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

Example 9 with SimpleResource

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);
    }
}
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

SimpleResource (com.bumptech.glide.load.resource.SimpleResource)9 SVG (com.caverock.androidsvg.SVG)8 Bitmap (android.graphics.Bitmap)4 Picture (android.graphics.Picture)4 PictureDrawable (android.graphics.drawable.PictureDrawable)4 SVGParseException (com.caverock.androidsvg.SVGParseException)4 Canvas (android.graphics.Canvas)2 Context (android.content.Context)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Nullable (android.support.annotation.Nullable)1 Nullable (androidx.annotation.Nullable)1 GlideBuilder (com.bumptech.glide.GlideBuilder)1 BitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Config (org.robolectric.annotation.Config)1