本文介绍了将CIImage转换为NSImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在玩Core Image框架。据我所知,如果我有一个图片( NSImage ),则需要先将其转换为 CIImage 。我可以这样做。
I'm playing with the Core Image framework. As I understand, if I have an image (NSImage), it needs to be converted into CIImage, first. I can do that.
NSImage *im1 = [[NSImage alloc] initWithContentsOfFile:imagepath];
NSRect rect1;rect1.size.width = img1.size.width; rect1.size.height = img1.size.height;
CGImageRef imageRef1 = [img1 CGImageForProposedRect:&rect1 context:[NSGraphicsContext currentContext] hints:nil];
CIImage *ciimage = [CIImage imageWithCGImage:imageRef1];
我有一个函数将核心图像过滤器应用于核心图像( CIImage ),我想测试。并且我想将输出图像作为子视图添加到窗口。所以我需要NSImage。如何将这个核心映像转换回NSImage?如果我问谷歌,我得不到好的结果。
I have a function that applies a Core Image filter to a core image (CIImage), which I want to test. And I want to add output image to a window as a subview. So I need NSImage. How can I convert this core image back into NSImage? If I ask Google, I don't get good results.
感谢您的帮助。
推荐答案
我没有测试,但我认为应该这样做:
I haven't tested it, but I think this should do it:
CIImage *ciImage = ...;
NSCIImageRep *rep = [NSCIImageRep imageRepWithCIImage:ciImage];
NSImage *nsImage = [[NSImage alloc] initWithSize:rep.size];
[nsImage addRepresentation:rep];
这篇关于将CIImage转换为NSImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!