NSTextField から CGImage を作成しようとしています。
私はこれである程度成功しました。それでも、テキストだけで構成される CGImage を取得できません。つまり、テキストフィールドをキャプチャするたびに、背景ウィンドウの色を取得しています.(アルファチャンネル情報を取得していないようです)
http://www.cocoadev.com/index.pl?ConvertNSImageToCGImageのスニペットに従ってみました
NSBitmapImageRep * bm = [NSBitmapImageRep alloc];
[theView lockFocus];
[bitmap initWithFocusedViewRect:[theView bounds]];
[theView unlockFocus]
[bma retain];// data provider will release this
int rowBytes, width, height;
rowBytes = [bm bytesPerRow];
width = [bm pixelsWide];
height = [bm pixelsHigh];
CGDataProviderRef provider = CGDataProviderCreateWithData( bm, [bm bitmapData], rowBytes * height, BitmapReleaseCallback );
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB );
CGBitmapInfo bitsInfo = kCGImageAlphaPremultipliedLast;
CGImageRef img = CGImageCreate( width, height, 8, 32, rowBytes, colorspace, bitsInfo, provider, NULL, NO, kCGRenderingIntentDefault );
CGDataProviderRelease( provider );
CGColorSpaceRelease( colorspace );
return img;
背景色なしでCGImageを取得するのに役立ちますか?