Create NSImageRep from CGImage

Daniel Peñalba 1 Reputation point

hi there! I’m trying to pinvoke the AppKit from C#. Any help would be appreciated.

I’m trying to create a new NSBitmapImageRep from a CGImage using the following constructor:

I’m trying the following C# code with no luck:

var nsBitmapImageRep = objc_getClass("NSBitmapImageRep");

 var nsBitmapImage = objc_msgSend_retIntPtr_IntPtr(

I’m not sure if this is the correct way to construct a new object …

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 27,106 Reputation points Microsoft Vendor


    If you are using AppKit and you want to create a new NSBitmapImageRep from a CGImage using the constructor in your Xamarin.Mac project, you could refer to the following code:

    var image = new NSImage("setting.png");// I create a NSImage to get the CGImage  
    var nsBitmapImageRep = new NSBitmapImageRep(image.CGImage);// this parameter is your CGImage   

    You also could check the API at

    Best Regards,
    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments