예제 #1
0
        public static SKBitmap GetPatternBitmap(this Paint paint, float scaleX, float scaleY, object currentFigure)
        {
            var pattern = paint?.Pattern;

            if (pattern == null)
            {
                return(null);
            }

            using (var context = new SkiaBitmapExportContext((int)(pattern.Width * scaleX), (int)(pattern.Height * scaleY), 1, disposeBitmap: false))
            {
                var canvas = context.Canvas;

                if (currentFigure != null)
                {
                }

                canvas.Scale(scaleX, scaleY);
                pattern.Draw(canvas);

                if (currentFigure != null)
                {
                }

                //var filename = "/storage/emulated/0/" + pattern.GetType().Name + ".png";
                //System.Console.WriteLine("Writing to :{0}",filename);
                //context.WriteToFile (filename);
                return(context.Bitmap);
            }
        }
예제 #2
0
        public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMode.Fit, bool disposeOriginal = false)
        {
            using (var context = new SkiaBitmapExportContext((int)width, (int)height, 1))
            {
                var fx = width / Width;
                var fy = height / Height;

                var w = Width;
                var h = Height;

                var x = 0f;
                var y = 0f;

                if (resizeMode == ResizeMode.Fit)
                {
                    if (fx < fy)
                    {
                        w *= fx;
                        h *= fx;
                    }
                    else
                    {
                        w *= fy;
                        h *= fy;
                    }

                    x = (width - w) / 2;
                    y = (height - h) / 2;
                }
                else if (resizeMode == ResizeMode.Bleed)
                {
                    if (fx > fy)
                    {
                        w *= fx;
                        h *= fx;
                    }
                    else
                    {
                        w *= fy;
                        h *= fy;
                    }

                    x = (width - w) / 2;
                    y = (height - h) / 2;
                }
                else
                {
                    w = width;
                    h = height;
                }

                context.Canvas.DrawImage(this, x, y, w, h);
                return(context.Image);
            }
        }
예제 #3
0
        public static SKBitmap GetPatternBitmap(this Paint paint, float scale = 1)
        {
            var pattern = paint?.Pattern;

            if (pattern == null)
            {
                return(null);
            }

            using (var context = new SkiaBitmapExportContext((int)(pattern.Width * scale), (int)(pattern.Height * scale), scale, disposeBitmap: false))
            {
                var canvas = context.Canvas;

                canvas.Scale(scale, scale);
                pattern.Draw(canvas);

                return(context.Bitmap);
            }
        }