J'essaie de créer CGImage à partir de NSTextField.
J'ai eu du succès avec ça. Cependant, je ne peux pas obtenir CGImage qui consiste en seulement du texte. Je veux dire que, chaque fois que la capture de l'textfield Je reçois la couleur de la fenêtre de fond avec elle. (On dirait que je ne reçois pas d'info de canal alpha)Récupération de CGImage à partir de NSView
J'ai essayé suivant extrait de 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;
Toute aide pour obtenir CGImage sans couleur de fond?
En fait, je vais générer des textures à partir de CGImage. En tout cas merci pour votre soln, je serai bientôt de retour. – shakthi
C'est bien. Toutes les méthodes ci-dessus produisent un NSImage ou NSBitmapImageRep dont vous pouvez créer un CGImage. – kperryua
Cela fonctionne très bien, merci. – shakthi