NSImage source from byte array Cocoa app Xamarin C#

Viewed 282

This is my first question there. I have created WPF application, which image control source is set to bitmap array of a random image. It works perfectly. The array contains information in the R,G,B order for each pixel.

Now, I have to do same thing in Cocoa app for Mac and I have a problem, because I'm doing it first time. I have created NSImageView, expose it as outlet and try to set Image as follows in ViewDidLoad() method:

 IMW.Image = GetImage();

 public static NSImage GetImage(){

   NSData nsdata = NSData.FromArray(bbb.ToArray()); // the same array as in WPF app
   NSBitmapImageRep nip = new NSBitmapImageRep(nsdata);
   NSImage image = new NSImage(nsdata);
   return image;

 }

There is always an error when try to run the app:

Could not initialize an instance of the type 'AppKit.NSBitmapImageRep': 
the native 'initWithData:' method returned nil.
It is possible to ignore this condition by setting 
MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.

Looks like there is a problem in the byte array, but I don't understand why it does work in the WPF app.

Thank you very much!

0 Answers
Related