如何从NSAttributedString创建剪贴蒙版?
|
我有一个NSAttributedString,我想将其绘制到CGImage中,以便以后可以将CGImage绘制到NSView中。这是我到目前为止的内容:
// Draw attributed string into NSImage
NSImage* cacheImage = [[NSImage alloc] initWithSize:NSMakeSize(w, h)];
[cacheImage lockFocus];
[attributedString drawWithRect:NSMakeRect(0, 0, width, height) options:0];
[cacheImage unlockFocus];
// Convert NSImage to CGImageRef
CGImageSourceRef source = CGImageSourceCreateWithData(
(CFDataRef)[cacheImage TIFFRepresentation], NULL);
CGImageRef img = CGImageSourceCreateImageAtIndex(source, 0, NULL);
我没有使用-[NSImage CGImageForProposedRect:context:hints],因为我的应用必须使用10.5 sdk。
当我使用CGContextDrawImage将其绘制到我的NSView中时,它将在文本周围绘制透明背景,从而使窗口后面的所有内容都可以显示出来。我想我想创建一个剪贴蒙版,但是我不知道该怎么做。
没有找到相关结果
已邀请:
1 个回复
旦彤