问题
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