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 Bitmap GetBitmapFromSvgString(string svgString, int width, int height) { var svg = SVGParser.ParseSVGFromString (svgString); 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 (svg.Picture, dst); } // Returns an immutable copy return Bitmap.CreateBitmap (bmp); }
public static Bitmap GetBitmapFromSvgRes(Android.Content.Res.Resources resources, int resID, int width, int height) { var svg = SVGParser.ParseSVGFromResource (resources, resID); 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 (svg.Picture, dst); } // Returns an immutable copy return Bitmap.CreateBitmap (bmp); }
public Bitmap GetPin(float ratio, int number, int width, int height, float alpha = 1) { int key = number + ((int)(ratio * 10000)) << 6; Bitmap bmp; if (pinCache.TryGetValue (key, out bmp)) return bmp; var svg = SVGParser.ParseSVGFromResource (context.Resources, Resource.Raw.pin, SvgColorMapperFactory.FromFunc (c => ColorReplacer (c, ratio, alpha))); bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888); using (var c = new Canvas (bmp)) { var dst = new RectF (0, 0, width, height); c.DrawPicture (svg.Picture, dst); c.DrawText (number.ToString (), width / 2 - 1, 16.ToPixels (), textPaint); } pinCache [key] = bmp; return bmp; }
protected override void DispatchDraw(Canvas canvas) { base.DispatchDraw (mPicture.BeginRecording (Width, Height)); mPicture.EndRecording (); int x = Width / 2; int y = Height / 2; if (false) canvas.DrawPicture (mPicture); else { DrawPict (canvas, 0, 0, x, y, 1, 1); DrawPict (canvas, x, 0, x, y, -1, 1); DrawPict (canvas, 0, y, x, y, 1, -1); DrawPict (canvas, x, y, x, y, -1, -1); } }
private void DrawPict(Canvas canvas, int x, int y, int w, int h, float sx, float sy) { canvas.Save (); canvas.Translate (x, y); canvas.ClipRect (0, 0, w, h); canvas.Scale (0.5f, 0.5f); canvas.Scale (sx, sy, w, h); canvas.DrawPicture (mPicture); canvas.Restore (); }