如何解决将NSBitmapImageRep转换为NSImage
我正在NSBitmapImageRep
和NSBitmapImageRep
之间切换(因为只有NSImage
可以让我找到每像素的颜色,但是NSImageView
只能用于NSImageCell
/ setImage
的{{1}})。我知道如何将NSImage
转换为NSBitmapImageRep
(使用bitmap = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]]
),但是我不能做相反的事情,因为TIFFRepresentation
是只读的。那么,如何将NSBitmapRep
转换为NSImage
?
充满希望,
radzo73
解决方法
从修改后的 NSBitmapImageRep 中取回 NSImage 所需要做的就是调用一个方法:
NSImage *image = [[NSImage alloc] initWithSize:someSize];
[...]
NSBitmapImageRep *rawImage = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
[code that gets and sets pixels]
[image initWithCGImage:[rawImage CGImage] size:image.size]; // overwrite original NSImage with modified one
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。