Exemple #1
0
        /// <summary>
        /// Open an image
        /// </summary>
        /// <param name="image">Byte array corresponding to the image</param>
        public void Open(byte[] image)
        {
            if (IsOpen)
            {
                throw new InvalidOperationException("An image is opened");
            }

            using (var stream = new MemoryStream(image))
            {
                using (var skStream = new SKManagedStream(stream))
                {
                    using (var codec = SKCodec.Create(skStream))
                    {
                        ImageInfo = codec.Info;
                    }
                }
            }

            using (var data = new SKData(image))
            {
                Image = SKImage.FromData(new SKData(image));
            }

            Surface     = SKSurface.Create(ImageInfo);
            Paint       = new SKPaint();
            Paint.Color = SKColor.Parse("#2ecc71");
            Surface.Canvas.DrawImage(Image, new SKRect(0f, 0f, ImageInfo.Width, ImageInfo.Height), new SKRect(0f, 0f, ImageInfo.Width, ImageInfo.Height), Paint);
            IsOpen = true;
        }
Exemple #2
0
 /// <summary>
 /// Draw another image on the immage
 /// </summary>
 /// <param name="image">Byte array corresponding to an image</param>
 /// <param name="bounds">Drawing bounds</param>
 public void DrawImage(byte[] image, Rectangle bounds)
 {
     using (var data = new SKData(image))
     {
         using (var skImage = SKImage.FromData(new SKData(image)))
         {
             var xScale = bounds.Width / skImage.Width;
             var yScale = bounds.Height / skImage.Height;
             Surface.Canvas.SetMatrix(SKMatrix.MakeScale(xScale, yScale));
             Surface.Canvas.DrawImage(skImage, bounds.X / xScale, bounds.Y / yScale);//We want to scale width & height, not X & Y
             Surface.Canvas.ResetMatrix();
         }
     }
 }