NSImage source from byte array Cocoa app Xamarin C#

做~自己de王妃 提交于 2021-02-09 09:27:24

问题


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!

来源:https://stackoverflow.com/questions/53060723/nsimage-source-from-byte-array-cocoa-app-xamarin-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!