Beispiel #1
0
        public async Task <byte[]> ExportCurrentImage(int width, int height, float scale, List <Abstractions.Stroke> strokes, Abstractions.Scaling scaling, Abstractions.ExportFormat format, int quality, Painter.Abstractions.Color BackgroundColor, bool useDevicePixelDensity, byte[] BackgroundImage = null)
        {
            if (scale == 0)
            {
                scale = 1.0f;
            }

            //Initialize data holders
            byte[] data;
            Stream str = new MemoryStream();

            if (useDevicePixelDensity)
            {
                width  *= (int)metrics.Density;
                height *= (int)metrics.Density;
            }

            Bitmap tempImage        = null;
            Bitmap backgroundBitmap = null;
            Canvas tempCanvas       = null;

            if (BackgroundImage == null)
            {
                tempImage  = Bitmap.CreateBitmap(metrics, width, height, Bitmap.Config.Argb8888);
                tempCanvas = new Canvas(tempImage);
            }
            else
            {
                backgroundBitmap = await BitmapFactory.DecodeByteArrayAsync(BackgroundImage, 0, BackgroundImage.Length);

                var backgroundScale = GetDrawingScale(scaling, backgroundBitmap, width, height);
                tempImage  = Bitmap.CreateBitmap(metrics, (int)Math.Min(width, backgroundBitmap.Width * backgroundScale), (int)Math.Min(height, backgroundBitmap.Height * backgroundScale), Bitmap.Config.Argb8888);
                tempCanvas = new Canvas(tempImage);
            }

            DrawStrokes(tempCanvas, strokes, backgroundBitmap, BackgroundColor, scaling, width, height, scale);

            //Compress the image and save it to the stream
            switch (format)
            {
            case Abstractions.ExportFormat.Png:
                await tempImage.CompressAsync(CompressFormat.Png, quality, str);

                break;

            case Abstractions.ExportFormat.Jpeg:
                await tempImage.CompressAsync(CompressFormat.Jpeg, quality, str);

                break;
            }

            //Memory management
            tempImage.Dispose();
            tempCanvas.Dispose();
            tempImage  = null;
            tempCanvas = null;

            //Read the data
            data = new byte[str.Length];
            str.Seek(0, SeekOrigin.Begin);
            await str.ReadAsync(data, 0, (int)str.Length);

            //Return the data
            return(data);
        }
Beispiel #2
0
 public async Task <byte[]> GetCurrentImageAsJPG(int width, int height, float scale, List <Abstractions.Stroke> strokes, Abstractions.Scaling scaling = Abstractions.Scaling.Relative_None, int quality = 80, Painter.Abstractions.Color BackgroundColor = null, bool useDevicePixelDensity = false, byte[] BackgroundImage = null)
 {
     return(await ExportCurrentImage(width, height, scale, strokes, scaling, Abstractions.ExportFormat.Jpeg, quality, BackgroundColor ?? new Abstractions.Color(1, 1, 1, 1), useDevicePixelDensity, BackgroundImage));
 }
 public async Task <byte[]> GetCurrentImageAsJPG(int width, int height, float scale, Abstractions.Scaling scaling = Abstractions.Scaling.Relative_None, int quality = 80, Painter.Abstractions.Color BackgroundColor = null)
 {
     return(await export.GetCurrentImageAsJPG(width, height, scale, Strokes, scaling, quality, BackgroundColor));
 }
Beispiel #4
0
        public async Task <byte[]> ExportCurrentImage(int width, int height, float scale, List <Abstractions.Stroke> strokes, Abstractions.Scaling scaling, Abstractions.ExportFormat format, int quality, Painter.Abstractions.Color BackgroundColor, bool useDevicePixelDensity, byte[] BackgroundImage = null)
        {
            //useDevicePixelDensity is not used on iOS

            UIImage image = drawPath(width, height, strokes);

            NSData imageData;

            if (format == Abstractions.ExportFormat.Png)
            {
                imageData = image.AsPNG();
            }
            else
            {
                imageData = image.AsJPEG(quality);
            }

            return(imageData.ToArray());
        }
Beispiel #5
0
 public async Task <byte[]> GetCurrentImageAsPNG(int width, int height, float scale, Abstractions.Scaling scaling = Abstractions.Scaling.Relative_None, int quality = 80, Painter.Abstractions.Color BackgroundColor = null, bool useDevicePixelDensity = false, byte[] BackgroundImage = null)
 {
     return(await export.GetCurrentImageAsPNG(width, height, scale, Strokes, scaling, quality, BackgroundColor, useDevicePixelDensity, BackgroundImage));
 }