glide icon indicating copy to clipboard operation
glide copied to clipboard

How to get a Bitmap from a SVG Url resource with Glide Version 4.11.0 ?

Open xiaogu-space opened this issue 5 years ago • 5 comments

xiaogu-space avatar Nov 23 '20 08:11 xiaogu-space

there is a sample here: https://github.com/bumptech/glide/tree/master/samples/svg If you add an SVG Decoder, will it work out of the box.

hnljp avatar Dec 16 '20 22:12 hnljp

there is a sample here: https://github.com/bumptech/glide/tree/master/samples/svg If you add an SVG Decoder, will it work out of the box.

but there no sample to get bitmap

xiaogu-space avatar Dec 23 '20 03:12 xiaogu-space

获取Bitmap,可以详细描述一下什么情况下获取BItmap吗?

44667788 avatar Sep 30 '21 14:09 44667788

@xiaogu-space did you solve this in the end?

I faced the same issue and managed to make it work:

  1. Take svg sample as base
  2. Replace all PictureDrawable with Bitmap
  3. Rename SvgDrawableTranscoder to SvgBitmapTranscoder
  4. In its constructor inject glide.getBitmapPool() in the module.
  5. In SvgBitmapTranscoder render SVG to Bitmap, e.g.
    Canvas canvas = new Canvas(bitmap);
    svg.renderToCanvas(canvas);
    return BitmapResource.obtain(bitmap, bitmapPool)
    
  6. Replace GlideApp.with(this).as(PictureDrawable.class)... with GlideApp.with(this).asBitmap().decode(SVG.class)...

TWiStErRob avatar Sep 27 '23 16:09 TWiStErRob

See also https://github.com/qoqa/glide-svg

TWiStErRob avatar Sep 27 '23 21:09 TWiStErRob