将NSImage *转换为CGImageRef? [英] Turning an NSImage* into a CGImageRef?

查看:606
本文介绍了将NSImage *转换为CGImageRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个简单的方法来做这个工作在10.5?

Is there an easy way to do this that works in 10.5?

在10.6中,我可以使用nsImage CGImageForProposedRect:NULL上下文:NULL hints:NULL

In 10.6 I can use nsImage CGImageForProposedRect: NULL context: NULL hints: NULL

使用1b黑白图像(像Group 4 TIFF),我可以使用位图,但cgbitmaps似乎不喜欢那个设置...有一个一般的方法这样做吗?

If I'm not using 1b black and white images (Like Group 4 TIFF), I can use bitmaps, but cgbitmaps seem to not like that setup... Is there a general way of doing this?

我需要这样做,因为我有一个IKImageView似乎只想添加CGImages,但我所有的是NSImages。目前,我使用一个私有的setImage:(NSImage *)方法,我真的真的,而不是使用...

I need to do this because I have an IKImageView that seems to only want to add CGImages, but all I've got are NSImages. Currently, I'm using a private setImage:(NSImage*) method that I'd REALLY REALLY rather not be using...

推荐答案

此网页上找到以下解决方案:

Found the following solution on 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+,所以你应该很好。

All the methods seem to be 10.4+ so you should be fine.

这篇关于将NSImage *转换为CGImageRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆