Does Glide have a method for loading both PNG and SVG?

后端 未结 7 1570
终归单人心
终归单人心 2020-11-29 06:34

I\'m using Glide to load some images asynchronously into some of my ImageViews, and I know it can handle images like PNG or

7条回答
  •  一整个雨季
    2020-11-29 07:09

    For others who reach this thread because they're looking for a way to load SVG's in Xamarin Android, the accepted answer won't work because a lot of those classes / methods don't seem to be available in the Xamarin Glide nuget package. Here is what worked for me:

    public static void SetSvgFromBytes (this ImageView imageView, byte[] bytes, int width, int height) {
                // Load the SVG from the bytes.
                var stream = new MemoryStream (bytes);
                var svg = SVG.GetFromInputStream (stream);
                // Create a Bitmap to render our SVG to.
                var bitmap = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
                // Create a Canvas to use for rendering.
                var canvas = new Canvas (bitmap);
                canvas.DrawRGB (255, 255, 255);
                // Now render the SVG to the Canvas.
                svg.RenderToCanvas (canvas);
                // Finally, populate the imageview from the Bitmap.
                imageView.SetImageBitmap (bitmap);
            }
    

    It requires the AndroidSVG.Xamarin nuget package.

提交回复
热议问题