-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSvgFactory.cs
87 lines (74 loc) · 2.88 KB
/
SvgFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.IO;
using Android.Graphics;
using Android.Graphics.Drawables;
namespace XamSvg
{
using Internals;
public static class SvgFactory
{
public static Bitmap GetBitmap (Android.Content.Res.Resources resources,
int resID,
int width, int height,
ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSVGFromResource (resources, resID, colorMapper);
return MakeBitmapFromSvg (svg, width, height);
}
public static Bitmap GetBitmap (string svgString, int width, int height,
ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSVGFromString (svgString, colorMapper);
return MakeBitmapFromSvg (svg, width, height);
}
public static Bitmap GetBitmap (TextReader reader, int width, int height,
ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSvgFromReader (reader, colorMapper);
return MakeBitmapFromSvg (svg, width, height);
}
public static Bitmap GetBitmap (Stream stream, int width, int height,
ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSvgFromStream (stream, colorMapper);
return MakeBitmapFromSvg (svg, width, height);
}
internal static Bitmap MakeBitmapFromSvg (Svg svg, int width, int height)
{
return MakeBitmapFromPicture (svg.Picture, width, height);
}
internal static Bitmap MakeBitmapFromPicture (Picture pic, int width, int height)
{
using (var bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
using (var c = new Canvas (bmp)) {
var dst = new RectF (0, 0, width, height);
c.DrawPicture (pic, dst);
}
// Returns an immutable copy
return Bitmap.CreateBitmap (bmp);
}
}
public static PictureBitmapDrawable GetDrawable (Android.Content.Res.Resources resources,
int resID,
ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSVGFromResource (resources, resID, colorMapper);
return new PictureBitmapDrawable (svg.Picture);
}
public static PictureBitmapDrawable GetDrawable (string svgString, ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSVGFromString (svgString, colorMapper);
return new PictureBitmapDrawable (svg.Picture);
}
public static PictureBitmapDrawable GetDrawable (TextReader reader, ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSvgFromReader (reader, colorMapper);
return new PictureBitmapDrawable (svg.Picture);
}
public static PictureBitmapDrawable GetDrawable (Stream stream, ISvgColorMapper colorMapper = null)
{
var svg = SVGParser.ParseSvgFromStream (stream, colorMapper);
return new PictureBitmapDrawable (svg.Picture);
}
}
}