Example #1
0
        public IBasicImage CreateImageFromByteArray(byte[] data, int width, int height)
        {
            IBasicImage image = null;
            NSImage imageResized = null;
            try
            {
                //Console.WriteLine("DisposableImageFactory - CreateImageFromByteArray - width: {0} height: {1}", width, height);
                NSGraphicsContext.GlobalRestoreGraphicsState();
                using (NSData imageData = NSData.FromArray(data))
                {
                    InvokeOnMainThread(() => {
                        using (NSImage imageFullSize = new NSImage(imageData))
                        {
                            try
                            {
                                imageResized = CoreGraphicsHelper.ScaleImageSquare(imageFullSize, width);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("DisposableImageFactory - Error resizing image: {0}", ex);
                            }
                        }
                    });
                }
                image = new BasicImage(imageResized);
                return image;
            }
            catch (Exception ex)
            {
                Console.WriteLine("DisposableImageFactory - Failed to process image: {0}", ex);
            }

            return image;
        }
 public IBasicImage RenderToImageInMemory()
 {
     NSImage image = null;
     InvokeOnMainThread(() => {
         //Console.WriteLine("MemoryGraphicsContextWrapper - RenderToImageInMemory");
         NSGraphicsContext.GlobalRestoreGraphicsState();
         image = new NSImage(new SizeF(BoundsWidth, BoundsHeight));
         image.AddRepresentation(_bitmap);
     });
     var basicImage = new BasicImage(image);
     return basicImage;
 }