Exemplo n.º 1
0
        private void Initialize()
        {
            imageView = new ImageView(context);
            imageView.SetBackgroundColor(Color.Transparent);

            drawingImageView = new ImageView(context);
            drawingImageView.SetBackgroundColor(Color.Transparent);

            StrokeColor     = new Abstractions.Color(0, 0, 0, 1);
            StrokeThickness = 1.0;

            IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            metrics = new DisplayMetrics();
            windowManager.DefaultDisplay.GetMetrics(metrics);

            AddView(imageView);
            AddView(drawingImageView);
        }
Exemplo n.º 2
0
        private void DrawStrokes(Canvas _canvas, List <Abstractions.Stroke> strokes, Bitmap backgroundBitmap, Abstractions.Color backgroundColor, Abstractions.Scaling backgroundScaling, int Width, int Height, float scale)
        {
            if (backgroundColor != null)
            {
                _canvas.DrawColor(new Color((byte)(backgroundColor.R * 255f), (byte)(backgroundColor.G * 255f), (byte)(backgroundColor.B * 255f)), PorterDuff.Mode.Src);
            }

            float deviceOrientation = 0;//TODO

            //TODO check the replacement for canvas.Save
            _canvas.Save(SaveFlags.Matrix);
            _canvas.Translate(_canvas.Width / 2f, _canvas.Height / 2f);
            _canvas.Rotate(deviceOrientation);
            _canvas.Translate(-(_canvas.Width / 2f), -(_canvas.Height / 2f));

            if (backgroundBitmap != null)
            {
                switch (backgroundScaling)
                {
                case Abstractions.Scaling.Absolute_None:
                case Abstractions.Scaling.Relative_None:
                    _canvas.DrawBitmap(backgroundBitmap, 0, 0, new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fit:
                case Abstractions.Scaling.Relative_Fit:
                    float backgroundScale = GetDrawingScale(backgroundScaling, backgroundBitmap, Width, Height);
                    _canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, (int)(backgroundBitmap.Width * backgroundScale), (int)(backgroundBitmap.Height * backgroundScale)), new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fill:
                case Abstractions.Scaling.Relative_Fill:
                    _canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, Width, Height), new Paint());
                    break;
                }
            }

            foreach (var stroke in strokes)
            {
                var paint = CreatePaint(stroke.StrokeColor.R, stroke.StrokeColor.G, stroke.StrokeColor.B, stroke.StrokeColor.A, stroke.Thickness, metrics.Density);

                var path = new Android.Graphics.Path();
                path.MoveTo((float)stroke.Points[0].X * scale, (float)stroke.Points[0].Y * scale);

                foreach (var p in stroke.Points)
                {
                    path.LineTo((float)p.X * scale, (float)p.Y * scale);
                }

                _canvas.DrawPath(path, paint);
            }
        }
Exemplo n.º 3
0
 public Task <byte[]> GetCurrentImageAsPNG(int width, int height, float scale, List <Stroke> strokes, Scaling scaling = Scaling.Relative_None, int quality = 80, Abstractions.Color BackgroundColor = null, bool useDevicePixelDensity = false, byte[] BackgroundImage = null)
 {
     return(nativePainter.GetCurrentImageAsPNG(width, height, scale, strokes, scaling, quality, BackgroundColor, useDevicePixelDensity, BackgroundImage));
 }
Exemplo n.º 4
0
 public Task <byte[]> ExportCurrentImage(int width, int height, float scale, List <Stroke> strokes, Scaling scaling, ExportFormat format, int quality, Abstractions.Color BackgroundColor, bool useDevicePixelDensity, byte[] BackgroundImage = null)
 {
     return(nativePainter.ExportCurrentImage(width, height, scale, strokes, scaling, format, quality, BackgroundColor, useDevicePixelDensity, BackgroundImage));
 }