首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将NSImage*变成CGImageRef?

将NSImage*变成CGImageRef?
EN

Stack Overflow用户
提问于 2010-03-31 03:27:20
回答 6查看 30.6K关注 0票数 15

有没有一种在10.5中工作的简单方法?

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

如果我不使用1b黑白图像(如Group 4 TIFF),我可以使用位图,但cgbitmap似乎不喜欢这种设置……有没有一种通用的方法来做这件事?

我需要这样做,因为我有一个似乎只想添加CGImages的IKImageView,但我得到的只有NSImages。目前,我正在使用一个私有的setImage:(NSImage*)方法,我真的不想使用它……

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2010-03-31 05:25:43

this page上找到了以下解决方案

代码语言:javascript
复制
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+的,所以你应该没问题。

票数 32
EN

Stack Overflow用户

发布于 2010-03-31 07:11:20

这是一条很长的路。仅当您仍支持旧版本的OS X时才应执行此操作。如果您需要10.6或更高版本,请改为使用just use the CGImage method。]

  1. Create a CGBitmapContext.
  2. Create an NSGraphicsContext for the bitmap context.
  3. Set the graphics context as the current context.
  4. Draw the image.
  5. Create the CGImage from the contents of the bitmap context.
  6. Release位图上下文。
票数 18
EN

Stack Overflow用户

发布于 2012-07-31 03:25:54

从雪豹开始,你可以通过向NSImage发送一条CGImageForProposedRect:context:hints:消息来实现ask the image to create a CGImage for you

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2548059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档