public void CreateMax()
        {
            TestRuntime.AssertXcodeVersion(8, 0);

            var first = new GColorConversionInfoTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConversionInfoTransformType.ApplySpace
            };
            var second = new GColorConversionInfoTriple()
            {
                Space     = CGColorSpace.CreateGenericGray(),
                Intent    = CGColorRenderingIntent.Perceptual,
                Transform = CGColorConversionInfoTransformType.FromSpace
            };
            var third = new GColorConversionInfoTriple()
            {
                Space     = CGColorSpace.CreateGenericXyz(),
                Intent    = CGColorRenderingIntent.Saturation,
                Transform = CGColorConversionInfoTransformType.ToSpace
            };

            using (var converter = new CGColorConversionInfo((NSDictionary)null, first, first, first)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
示例#2
0
        public void CreateMax()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(9, 3))
            {
                Assert.Ignore("requires iOS 9.3+");
            }

            var first = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };
            var second = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericGray(),
                Intent    = CGColorRenderingIntent.Perceptual,
                Transform = CGColorConverterTransformType.FromSpace
            };
            var third = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericXyz(),
                Intent    = CGColorRenderingIntent.Saturation,
                Transform = CGColorConverterTransformType.ToSpace
            };

            using (var converter = new CGColorConverter(null, first, first, first)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
示例#3
0
        public void IrradianceAtPointTest()
        {
            using (var obj = new MDLLight()) {
                var color = obj.GetIrradiance(new Vector3(1, 2, 3));
                if (Runtime.Arch == Arch.SIMULATOR && Environment.OSVersion.Version.Major < 15)
                {
                    Assert.IsNull(color, "color 1");
                }
                else
                {
                    Assert.IsNotNull(color, "color 1");
                }
            }

            using (var obj = new MDLLight()) {
                var color = obj.GetIrradiance(new Vector3(1, 2, 3), CGColorSpace.CreateGenericRgb());
                if (Runtime.Arch == Arch.SIMULATOR && Environment.OSVersion.Version.Major < 15)
                {
                    Assert.IsNull(color, "color 2");
                }
                else
                {
                    Assert.IsNotNull(color, "color 2");
                }
            }
        }
        public void CreateSimple()
        {
            TestRuntime.AssertXcodeVersion(8, 0);

            using (var from = CGColorSpace.CreateGenericGray())
                using (var to = CGColorSpace.CreateGenericRgb())
                    using (var converter = new CGColorConversionInfo(from, to)) {
                        Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                    }
        }
示例#5
0
        public void IrradianceAtPointTest()
        {
            using (var obj = new MDLLight()) {
                var color = obj.GetIrradiance(new Vector3(1, 2, 3));
                Assert.IsNotNull(color, "color 1");
            }

            using (var obj = new MDLLight()) {
                var color = obj.GetIrradiance(new Vector3(1, 2, 3), CGColorSpace.CreateGenericRgb());
                Assert.IsNotNull(color, "color 2");
            }
        }
示例#6
0
        public void CreateSimple()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(9, 3))
            {
                Assert.Ignore("requires iOS 9.3+");
            }

            using (var from = CGColorSpace.CreateGenericGray())
                using (var to = CGColorSpace.CreateGenericRgb())
                    using (var converter = new CGColorConverter(from, to)) {
                        Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                    }
        }
        public void CreateSimple_GetINativeObject()
        {
            TestRuntime.AssertXcodeVersion(8, 0);

            using (var from = CGColorSpace.CreateGenericGray())
                using (var to = CGColorSpace.CreateGenericRgb()) {
                    var handle = CGColorConversionInfoCreate(from == null ? IntPtr.Zero : from.Handle,
                                                             to == null ? IntPtr.Zero : to.Handle);
                    using (var o = Runtime.GetINativeObject <CGColorConversionInfo> (handle, false)) {
                        Assert.That(o.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                    }
                }
        }
 public void CGColorSpace_CGColorSpace_NSDictionary()
 {
     TestRuntime.AssertXcodeVersion(11, 0);
     using (var from = CGColorSpace.CreateGenericGray())
         using (var to = CGColorSpace.CreateGenericRgb()) {
             using (var converter = new CGColorConversionInfo(from, to, (NSDictionary)null)) {
                 Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle - null");
             }
             using (var d = new NSDictionary())
                 using (var converter = new CGColorConversionInfo(from, to, d)) {
                     Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                 }
         }
 }
        public void CreateDual()
        {
            TestRuntime.AssertXcodeVersion(7, 3);

            var triple = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };

            using (var converter = new CGColorConverter(null, triple, triple)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
        public void CGColorSpace_CGColorSpace_CGColorConversionOptions()
        {
            TestRuntime.AssertXcodeVersion(11, 0);
            using (var from = CGColorSpace.CreateGenericGray())
                using (var to = CGColorSpace.CreateGenericRgb()) {
                    using (var converter = new CGColorConversionInfo(from, to, (CGColorConversionOptions)null)) {
                        Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle-null");
                    }

                    var o = new CGColorConversionOptions();
                    o.BlackPointCompensation = true;
                    using (var converter = new CGColorConversionInfo(from, to, o)) {
                        Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                    }
                }
        }
示例#11
0
        public void CreateSimple_GetINativeObject()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(9, 3))
            {
                Assert.Ignore("requires iOS 9.3+");
            }

            using (var from = CGColorSpace.CreateGenericGray())
                using (var to = CGColorSpace.CreateGenericRgb()) {
                    var handle = CGColorConverterCreateSimple(from == null ? IntPtr.Zero : from.Handle,
                                                              to == null ? IntPtr.Zero : to.Handle);
                    using (var o = Runtime.GetINativeObject <CGColorConverter> (handle, false)) {
                        Assert.That(o.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                    }
                }
        }
示例#12
0
        public void CreateDual()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(9, 3))
            {
                Assert.Ignore("requires iOS 9.3+");
            }

            var triple = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };

            using (var converter = new CGColorConverter(null, triple, triple)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
示例#13
0
        public void Setup()
        {
            if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                Assert.Ignore("Requires iOS9+");
            }

            if (Runtime.Arch == Arch.SIMULATOR && IntPtr.Size == 4)
            {
                // There's a bug in the i386 version of objc_msgSend where it doesn't preserve SIMD arguments
                // when resizing the cache of method selectors for a type. So here we call all selectors we can
                // find, so that the subsequent tests don't end up producing any cache resize (radar #21630410).
                using (var obj = new MDLLight()) {
                    obj.GetIrradiance(Vector3.Zero);
                    obj.GetIrradiance(Vector3.Zero, CGColorSpace.CreateGenericRgb());
                }
            }
        }
示例#14
0
        protected override void Attached(SciterElement se)
        {
            int width  = 400;
            int height = 400;

            byte[] data = new byte[width * height * 4];
            var    ctx  = new CGBitmapContext(data, width, height, 8, width * 4, CGColorSpace.CreateGenericRgb(), CGImageAlphaInfo.PremultipliedLast);

            ctx.SetFillColor(new CGColor(100, 0, 0));
            ctx.SetStrokeColor(new CGColor(0, 0, 100));
            ctx.SetLineWidth(2);

            //ctx.AddPath(_svg._cgpath);
            //ctx.DrawPath(CGPathDrawingMode.FillStroke);

            _simg = new SciterImage(ctx.ToImage());
            //se.SetStyle("width", img.Width + "px");
            //se.SetStyle("height", img.Height + "px");
        }
示例#15
0
        protected override void UpdateCapturedImage()
        {
            if (view != null && layer == null)
            {
                var bitmap = view.BitmapImageRepForCachingDisplayInRect(view.Bounds);
                if (bitmap == null)
                {
                    return;
                }

                view.CacheDisplay(view.Bounds, bitmap);
                var data = bitmap.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png);
                CapturedImage = data.ToArray();
            }
            else if (layer != null)
            {
                var  scale       = layer.ContentsScale;
                nint h           = (nint)(layer.Bounds.Height * scale);
                nint w           = (nint)(layer.Bounds.Width * scale);
                nint bytesPerRow = w * 4;

                if (h <= 0 || w <= 0)
                {
                    return;
                }

                using (var colorSpace = CGColorSpace.CreateGenericRgb())
                    using (var context = new CGBitmapContext(IntPtr.Zero, w, h, 8, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedLast)) {
                        // Apply a flipping transform because layers are apparently weird.
                        var transform = new CGAffineTransform(scale, 0, 0, -scale, 0, h);
                        context.ConcatCTM(transform);

                        layer.RenderInContext(context);

                        using (var image = context.ToImage())
                            using (var bitmap = new NSBitmapImageRep(image)) {
                                var data = bitmap.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png);
                                CapturedImage = data.ToArray();
                            }
                    }
            }
        }
        public void CreateDual()
        {
            TestRuntime.AssertXcodeVersion(8, 0);

            var triple = new GColorConversionInfoTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConversionInfoTransformType.ApplySpace
            };

            var options = new CGColorConversionOptions()
            {
                BlackPointCompensation = true
            };

            using (var converter = new CGColorConversionInfo((CGColorConversionOptions)null, triple, triple)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
示例#17
0
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor(Type.EmptyTypes);

            if ((ctor != null) && !ctor.IsAbstract)
            {
                return(ctor.Invoke(null) as INativeObject);
            }

            if (!NativeObjectInterfaceType.IsAssignableFrom(t))
            {
                throw new ArgumentException("t");
            }
            switch (t.Name)
            {
            case "CFAllocator":
                return(CFAllocator.SystemDefault);

            case "CFBundle":
                var bundles = CFBundle.GetAll();
                if (bundles.Length > 0)
                {
                    return(bundles [0]);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
                }

            case "CFNotificationCenter":
                return(CFNotificationCenter.Darwin);

            case "CFReadStream":
            case "CFStream":
                CFReadStream  readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(readStream);

            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(writeStream);

            case "CFUrl":
                return(CFUrl.FromFile("/etc"));

            case "CFPropertyList":
                return(CFPropertyList.FromData(NSData.FromString("<string>data</string>")).PropertyList);

            case "DispatchData":
                return(DispatchData.FromByteBuffer(new byte [] { 1, 2, 3, 4 }));

            case "AudioFile":
                var path = Path.GetFullPath("1.caf");
                var af   = AudioFile.Open(CFUrl.FromFile(path), AudioFilePermission.Read, AudioFileType.CAF);
                return(af);

            case "CFHTTPMessage":
                return(CFHTTPMessage.CreateEmpty(false));

            case "CFMutableString":
                return(new CFMutableString("xamarin"));

            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB()) {
                    return(new CGBitmapContext(data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast));
                }

            case "CGContextPDF":
                var filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl(filename))
                    return(new CGContextPDF(url));

            case "CGColorConversionInfo":
                var cci = new GColorConversionInfoTriple()
                {
                    Space     = CGColorSpace.CreateGenericRgb(),
                    Intent    = CGColorRenderingIntent.Default,
                    Transform = CGColorConversionInfoTransformType.ApplySpace
                };
                return(new CGColorConversionInfo((NSDictionary)null, cci, cci, cci));

            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData()) {
                    return(new CGDataConsumer(destData));
                }

            case "CGDataProvider":
                filename = "xamarin1.png";
                return(new CGDataProvider(filename));

            case "CGFont":
                return(CGFont.CreateWithFontName("Courier New"));

            case "CGPattern":
                return(new CGPattern(
                           new RectangleF(0, 0, 16, 16),
                           CGAffineTransform.MakeIdentity(),
                           16, 16,
                           CGPatternTiling.NoDistortion,
                           true,
                           (cgc) => {}));

            case "CMBufferQueue":
                return(CMBufferQueue.CreateUnsorted(2));

            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
                {
                    FamilyName = "Courier",
                    StyleName  = "Bold",
                    Size       = 16.0f
                };
                using (var fd = new CTFontDescriptor(fda))
                    return(new CTFont(fd, 10));

            case "CTFontCollection":
                return(new CTFontCollection(new CTFontCollectionOptions()));

            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes();
                return(new CTFontDescriptor(fda));

            case "CTTextTab":
                return(new CTTextTab(CTTextAlignment.Left, 2));

            case "CTTypesetter":
                return(new CTTypesetter(new NSAttributedString("Hello, world",
                                                               new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTFrame":
                var framesetter = new CTFramesetter(new NSAttributedString("Hello, world",
                                                                           new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                }));
                var bPath = UIBezierPath.FromRect(new RectangleF(0, 0, 3, 3));
                return(framesetter.GetFrame(new NSRange(0, 0), bPath.CGPath, null));

            case "CTFramesetter":
                return(new CTFramesetter(new NSAttributedString("Hello, world",
                                                                new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTGlyphInfo":
                return(new CTGlyphInfo("copyright", new CTFont("ArialMY", 24), "Foo"));

            case "CTLine":
                return(new CTLine(new NSAttributedString("Hello, world",
                                                         new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CGImageDestination":
                var storage = new NSMutableData();
                return(CGImageDestination.Create(new CGDataConsumer(storage), "public.png", 1));

            case "CGImageMetadataTag":
                using (NSString name = new NSString("tagName"))
                    using (var value = new NSString("value"))
                        return(new CGImageMetadataTag(CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value));

            case "CGImageSource":
                filename = "xamarin1.png";
                return(CGImageSource.FromUrl(NSUrl.FromFilename(filename)));

            case "SecPolicy":
                return(SecPolicy.CreateSslPolicy(false, null));

            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle)));
                }

            case "SecTrust":
                X509Certificate x = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust(x, policy));

            case "SslContext":
                return(new SslContext(SslProtocolSide.Client, SslConnectionType.Stream));

            case "UIFontFeature":
                return(new UIFontFeature(CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

            case "NetworkReachability":
                return(new NetworkReachability(IPAddress.Loopback, null));

            case "VTCompressionSession":
            case "VTSession":
                return(VTCompressionSession.Create(1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes)null));

            case "VTFrameSilo":
                return(VTFrameSilo.Create());

            case "VTMultiPassStorage":
                return(VTMultiPassStorage.Create());

            case "CFString":
                return(new CFString("test"));

            case "DispatchBlock":
                return(new DispatchBlock(() => { }));

            case "DispatchQueue":
                return(new DispatchQueue("com.example.subsystem.taskXYZ"));

            case "DispatchGroup":
                return(DispatchGroup.Create());

            case "CGColorSpace":
                return(CGColorSpace.CreateDeviceCmyk());

            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return(new CGGradient(null, cArray));

            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider(filename))
                    return(CGImage.FromPNG(dp, null, false, CGColorRenderingIntent.Default));

            case "CGColor":
                return(UIColor.Black.CGColor);

            case "CMClock":
                return(CMClock.HostTimeClock);

            case "CMTimebase":
                return(new CMTimebase(CMClock.HostTimeClock));

            case "CVPixelBufferPool":
                return(new CVPixelBufferPool(
                           new CVPixelBufferPoolSettings(),
                           new CVPixelBufferAttributes(CVPixelFormatType.CV24RGB, 100, 50)
                           ));

            case "SecCertificate":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate(cdata));

            case "SecCertificate2":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate2(new SecCertificate(cdata)));

            case "SecTrust2":
                X509Certificate x2 = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust2(new SecTrust(x2, policy)));

            case "SecIdentity2":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity2(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle))));
                }

            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord(SecKind.Key)) {
                    record.KeyType       = SecKeyType.RSA;
                    record.KeySizeInBits = 512;                     // it's not a performance test :)
                    SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key);
                    return(private_key);
                }

            case "SecAccessControl":
                return(new SecAccessControl(SecAccessible.WhenPasscodeSetThisDeviceOnly));

            default:
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
            }
        }
示例#18
0
        public UIImage Load(string name, Stream stream, IImageTransform transform)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Image <PIXELFMT> sharpImg = Image.Load <PIXELFMT>(stream);
            var argb   = MemoryMarshal.Cast <PIXELFMT, int>(sharpImg.GetPixelSpan()).ToArray();
            var width  = sharpImg.Width;
            var height = sharpImg.Height;

            // This is why I can't just use CoreGraphics to load the image directly.
            if (transform != null)
            {
                argb = transform.Transform(argb, width, height);
            }

            // Coerce into an iOS image. Only premultiplied variants are supported.
            var flags = CGBitmapFlags.ByteOrder32Little | CGBitmapFlags.PremultipliedFirst;

            for (int i = 0; i < argb.Length; i++)
            {
                int aarrggbb = argb[i];
                int aa       = (aarrggbb >> 24) & 0xff;
                int rr00bb   = aarrggbb & 0xff00ff;
                int gg00     = aarrggbb & 0xff00;
                int rr00bb00 = (rr00bb * aa) & ~0xff00ff;
                int gg0000   = (gg00 * aa) & 0xff0000;
                argb[i] = (aarrggbb & ~0x00ffffff) | (((rr00bb00 | gg0000) >> 8) & 0xffffff);
            }

            // The "safe" alternative of GCHandle.Alloc didn't work for me.
            unsafe
            {
                fixed(int *pBuf = argb)
                {
                    var ctxt = new CGBitmapContext(new IntPtr((void *)pBuf), width, height, 8, 4 * width, CGColorSpace.CreateGenericRgb(), flags);
                    var img  = new UIImage(ctxt.ToImage());

                    return(img);
                }
            }
        }
示例#19
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (!drawInit)
            {
                this.Window.Title = "PixelFarm";
                drawInit          = true;
                destImg           = new ActualImage(destImgW, destImgH, PixelFarm.Agg.PixelFormat.ARGB32);
                imgGfx2d          = new ImageGraphics2D(destImg);        //no platform
                p      = new AggCanvasPainter(imgGfx2d);
                stride = destImg.Stride;
                LoadGlyphs();
            }
            //base.Draw(rect);
            base.DrawRect(dirtyRect);


            p.Clear(Color.Yellow);
            p.FillColor = Color.Black;
            p.Fill(vxs);

            var            data     = Foundation.NSData.FromArray(ActualImage.GetBuffer(destImg));
            CGDataProvider provider = new CGDataProvider(data);

            using (var myImg2 = new CGImage(
                       destImgW, destImgH,
                       8, 32,
                       stride, CGColorSpace.CreateGenericRgb(),
                       CGBitmapFlags.PremultipliedLast,
                       provider,
                       null, true,
                       CGColorRenderingIntent.AbsoluteColorimetric))

                using (var nsGraphics = AppKit.NSGraphicsContext.CurrentContext)
                {
                    CGContext g      = nsGraphics.CGContext;
                    CGColor   color0 = new CGColor(1, 1, 1, 1);
                    g.SetFillColor(color0);
                    //g.ClearRect(new CGRect(0, 0, 800, 600));
                    //----------

                    CGColor color1 = new CGColor(1, 0, 0, 1);
                    g.SetFillColor(color1);

                    CGRect s1    = CGRect.FromLTRB(0, 0, 50, 50);
                    CGPath gpath = new CGPath();
                    gpath.AddRect(CGAffineTransform.MakeTranslation(20, 20), s1);
                    g.AddPath(gpath);
                    g.FillPath();


                    CGRect s2 = new CGRect(50, 50, destImgW, destImgH);
                    g.DrawImage(s2, myImg2);

                    //

                    //g.FillRect(s1);

                    CGColor color2 = new CGColor(0, 0, 1, 1);
                    g.SetFillColor(color2);
                    g.TranslateCTM(30, 30);


                    var strAttr = new CTStringAttributes
                    {
                        ForegroundColorFromContext = true,
                        Font = new CTFont("Arial", 24)
                    };


                    g.ScaleCTM(1, -1);            //flip
                    NSAttributedString a_str = new NSAttributedString("abcd", strAttr);
                    using (CTLine line = new CTLine(a_str))
                    {
                        line.Draw(g);
                    }


                    ////if (chkBorder.Checked)
                    ////{
                    ////	//5.4
                    ////	p.StrokeColor = PixelFarm.Drawing.Color.Green;
                    ////	//user can specific border width here...
                    ////	//p.StrokeWidth = 2;
                    ////	//5.5
                    ////	p.Draw(vxs);
                    ////}
                    ////6. use this util to copy image from Agg actual image to System.Drawing.Bitmap
                    //BitmapHelper.CopyToWindowsBitmap(destImg, winBmp, new RectInt(0, 0, 300, 300));
                    ////---------------
                    ////7. just render our bitmap
                    //g.ClearRect(rect);

                    //g.DrawImage(winBmp, new Point(10, 0));
                }



            //// scale and translate the CTM so the image appears upright
            //g.ScaleCTM (1, -1);
            //g.TranslateCTM (0, -Bounds.Height);
            //g.DrawImage (rect, UIImage.FromFile ("MyImage.png").CGImage);
            //// translate the CTM by the font size so it displays on screen
            //float fontSize = 35f;
            //g.TranslateCTM (0, fontSize);

            //// set general-purpose graphics state
            //g.SetLineWidth (1.0f);
            //g.SetStrokeColor (UIColor.Yellow.CGColor);
            //g.SetFillColor (UIColor.Red.CGColor);
            //g.SetShadow (new CGSize (5, 5), 0, UIColor.Blue.CGColor);

            //// set text specific graphics state
            //g.SetTextDrawingMode (CGTextDrawingMode.FillStroke);
            //g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman);

            //// show the text
            //g.ShowText ("Hello Core Graphics");
        }