protected override bool OnExposeEvent(Gdk.EventExpose evnt) { var window = evnt.Window; // get the pixbuf var imgInfo = CreateDrawingObjects(); if (imgInfo.Width == 0 || imgInfo.Height == 0) { return(true); } // start drawing using (new SKAutoCanvasRestore(surface.Canvas, true)) { OnPaintSurface(new SKPaintSurfaceEventArgs(surface, imgInfo)); } surface.Canvas.Flush(); // swap R and B if (imgInfo.ColorType == SKColorType.Bgra8888) { using (var pixmap = surface.PeekPixels()) { SKSwizzle.SwapRedBlue(pixmap.GetPixels(), imgInfo.Width * imgInfo.Height); } } // write the pixbuf to the graphics window.Clear(); window.DrawPixbuf(null, pix, 0, 0, 0, 0, imgInfo.Width, imgInfo.Height, Gdk.RgbDither.None, 0, 0); return(true); }
protected override bool OnDrawn(Context cr) { // get the pixbuf var imgInfo = CreateDrawingObjects(); if (imgInfo.Width == 0 || imgInfo.Height == 0) { return(true); } // start drawing using (new SKAutoCanvasRestore(surface.Canvas, true)) { OnPaintSurface(new SKPaintSurfaceEventArgs(surface, imgInfo)); } surface.Canvas.Flush(); pix.MarkDirty(); // swap R and B if (imgInfo.ColorType == SKColorType.Rgba8888) { using (var pixmap = surface.PeekPixels()) { SKSwizzle.SwapRedBlue(pixmap.GetPixels(), imgInfo.Width * imgInfo.Height); } } // write the pixbuf to the graphics cr.SetSourceSurface(pix, 0, 0); cr.Paint(); return(true); }
private SKPixmap DrawMarker(SKPin sharedMarker) { double bitmapWidth = sharedMarker.Width * Context.Resources.DisplayMetrics.Density; double bitmapHeight = sharedMarker.Height * Context.Resources.DisplayMetrics.Density; SKSurface surface = SKSurface.Create((int)bitmapWidth, (int)bitmapHeight, SKColorType.Rgba8888, SKAlphaType.Premul); surface.Canvas.Clear(SKColor.Empty); sharedMarker.DrawPin(surface); return(surface.PeekPixels()); }
private Task <UIImage> RenderPinAsync(SKPin pin, CancellationToken token = default(CancellationToken)) { return(Task.Run(() => { double bitmapWidth = pin.Width * _screenDensity; double bitmapHeight = pin.Height * _screenDensity; using (SKSurface surface = SKSurface.Create((int)bitmapWidth, (int)bitmapHeight, SKColorType.Rgba8888, SKAlphaType.Premul)) { surface.Canvas.Clear(SKColor.Empty); pin.DrawPin(surface); return surface.PeekPixels().ToUIImage(); } }, token)); }