来自字节数组的 NSImage
我正在尝试在 NSImageView 中显示图像,图像包含在字节数组中。我该怎么做?据我了解,我需要将 byte[] 转换为 NSData 变量并将其提供给 NSImage。这是正确的吗?我该怎么做?我尝试过强制转换,但不起作用,而且似乎没有内置任何转换...
我尝试了以下操作:
强制转换:
NSData bytesAsMacVariable = (NSData) imageAsBytes;
也尝试过
NSData bytesAsMacVariable = imageAsBytes as NSData;
最后,尝试传递一个 byte[] ,就好像它是一个 NSData。
NSImage imageToShow = new NSImage(imageAsBytes);
这些都不起作用,据我所知, NSImage 或 NSData 都没有接受 byte[] 进行转换的成员函数......
I'm trying to display an image in a NSImageView, with an image contained in a Byte array. How can I do this? From what I understand I need to convert my byte[] to an NSData variable and feed that to an NSImage. Is this correct? How do I do it? I've tried casting and that doesn't work, and there doesn't seem to be any conversion built in...
I have tried the following:
Casting:
NSData bytesAsMacVariable = (NSData) imageAsBytes;
Also tried
NSData bytesAsMacVariable = imageAsBytes as NSData;
Finally, tried to pass a byte[] as if it was a NSData.
NSImage imageToShow = new NSImage(imageAsBytes);
None of these will work, and as far as I can see, neither NSImage or NSData has a member function that accepts byte[] for conversion...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在转换为对象类型,但您应该转换为指向对象的指针类型。
尝试更多类似的东西
指针非常重要。
You're casting to the object type, but you should cast to pointer-to-object type.
Try something more like
The pointers are very important.
您可以使用 NSMutableData,如下所示:
You can use an NSMutableData, like this: