我試圖採取一個NSString和光柵處理了爲位圖(字節數組(RGBA))如何柵格化字符串(MAC)
我已經得到的任何信息如何最接近做這樣的事情是在一個論壇上發帖,暗示沿
NSString *myString = [[NSString alloc] initWithString:@"This is a test"];
NSSize size = {256, 256};
NSImage *myImage = [[NSImage alloc] initWithSize:size];
[myImage lockFocus];
// if you have a second image you're going to overlay on top of the first, do the same except use NSCompositeSourceOver as the operation
[myString drawAtPoint: NSMakePoint(0, 0)];
[myImage unlockFocus];
NSData *tiffData = [myImage TIFFRepresentation];
線的東西不幸的是,應用程序凍結/在[MYIMAGE lockFocus]崩潰。
我也研究過在CoreGraphics中這樣做,但我發現更少的信息。我得到的點點滴滴,即位圖的背景和字體對象,但沒有什麼暗示去,「柵格化這個字符串」
如果有人上了車如何做到這一點的一些想法,那將不勝感激
謝謝。
我剛剛注意到了this,這是我明確表示這對我來說是新的。我可以使用CGBitmapContextCreate創建一個CGContextRef,然後使用UIGraphicsPushContext「推送」它,這樣任何後續的drawAtPoint都可以呈現給上下文ref?對不起,我現在想的很大。我應該試試看。 UIGraphicsPushContext是一個UIKit方法,不幸意味着iPhone只有我知道。