Forum Xamarin Xamarin.iOS

How to merge two NSImage into one?

MatteoRisoMatteoRiso USMember ✭✭
edited July 2017 in Xamarin.iOS

Hello. I'm trying to draw a NSImage from Resources on top of another NSImage so I could merge them together.
I'm testing the following code, which is very similar to the one used to draw text on NSImage available in a different post:

public static CGImage DrawLogo(NSImage uiImage)
            nfloat fWidth = uiImage.Size.Width;
            nfloat fHeight = uiImage.Size.Height;

            using (CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, (nint)fWidth, (nint)fHeight, 8, 4 * (nint)fWidth, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst))

                ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), uiImage.CGImage);
                NSImage qrLogo = NSImage.ImageNamed("qrLogo");
                ctx.DrawImage(new CGRect(0, 0, 72, 72,qrLogo.CGImage);
                return ctx.ToImage();

Unfortunately, this code does nothing and all I get is just the first NSImage ("uiImage") without the second one drawn as an overlay.
What am I doing wrong?


Sign In or Register to comment.