有没有一种在10.5中工作的简单方法?
在10.6中,我可以使用nsImage CGImageForProposedRect: NULL上下文: NULL提示: NULL
如果我不使用1b黑白图像(如Group 4 TIFF),我可以使用位图,但cgbitmap似乎不喜欢这种设置……有没有一种通用的方法来做这件事?
我需要这样做,因为我有一个似乎只想添加CGImages的IKImageView,但我得到的只有NSImages。目前,我正在使用一个私有的setImage:(NSImage*)方法,我真的不想使用它……
发布于 2010-03-31 05:25:43
在this page上找到了以下解决方案
NSImage* someImage;
// create the image somehow, load from file, draw into it...
CGImageSourceRef source;
source = CGImageSourceCreateWithData((CFDataRef)[someImage TIFFRepresentation], NULL);
CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);所有的方法似乎都是10.4+的,所以你应该没问题。
发布于 2010-03-31 07:11:20
这是一条很长的路。仅当您仍支持旧版本的OS X时才应执行此操作。如果您需要10.6或更高版本,请改为使用just use the CGImage method。]
发布于 2012-07-31 03:25:54
从雪豹开始,你可以通过向NSImage发送一条CGImageForProposedRect:context:hints:消息来实现ask the image to create a CGImage for you。
https://stackoverflow.com/questions/2548059
复制相似问题