osx - How to- NSAttributedString to CGImageRef -


i'm writing quicklook plugin. well, works. want try make better ;). question.
here function returns thumbnail image , i'm using now.

qlthumbnailrequestsetimagewithdata( qlthumbnailrequestref thumbnail, cfdataref data, cfdictionaryref properties); ); 

http://developer.apple.com/mac/library/documentation/userexperience/reference/qlthumbnailrequest_ref/reference/reference.html#//apple_ref/c/func/qlthumbnailrequestsetimagewithdata

right i'm creating tiff -> encapsulated nsdata. example

// setting cfdataref cgsize thumbnailmaxsize = qlthumbnailrequestgetmaximumsize(thumbnail); nsmutableattributedstring *attributedstring = [[[nsmutableattributedstring alloc]                                                     initwithstring:@"dummy"                                                     attributes:[nsdictionary dictionarywithobjectsandkeys:                                                                [nsfont fontwithname:@"monaco" size:10], nsfontattributename,                                                                 [nscolor colorwithcalibratedred:0.0 green:0.0 blue:0.0 alpha:1.0], nsforegroundcolorattributename,                                                                 nil]                                                    ] autorelease]; nsimage *thumbnailimage = [[[nsimage alloc] initwithsize:nsmakesize(thumbnailmaxsize.width, thumbnailmaxsize.height)] autorelease]; [thumbnailimage lockfocus]; [[nscolor whitecolor] set]; nsrectfill(nsmakerect(0, 0, thumbnailmaxsize.width, thumbnailmaxsize.height)); [attributedstring drawinrect:nsmakerect(0, 0, thumbnailmaxsize.width, thumbnailmaxsize.height)]; [thumbnailimage unlockfocus]; (cfdataref)[thumbnailimage tiffrepresentation]; // data  // setting cfdictionaryref (cfdictionaryref)[nsdictionary dictionarywithobjectsandkeys:@"kuttypetiff", (nsstring *)kcgimagesourcetypeidentifierhint, nil ]; // properties 

however quicklook provides function return thumbnail image, namely

qlthumbnailrequestsetimage( qlthumbnailrequestref thumbnail, cgimageref image, cfdictionaryref properties); ); 

http://developer.apple.com/mac/library/documentation/userexperience/reference/qlthumbnailrequest_ref/reference/reference.html#//apple_ref/c/func/qlthumbnailrequestsetimage

i have feeling passing cgimage ql instead of tiff data in speeding things up. however- have never worked cg context before. know, documentation there :), anyways- give example how turn nsattributed string cgimageref. example worth 10 times reading documentation ;)
appreciated. in advance!

could give example how turn nsattributed string cgimageref.

you can't turn string image; they're 2 different kinds of data, , 1 2 dimensional (characters on time) while other at-least-three dimensional (color on x , y).

what need draw string , produce image of drawing. that's you're doing nsimage: creating image , drawing string it.

you're asking creating cgimage. creating bitmap context, using core text draw string it, , creating image of contents of bitmap context 1 way that.

however, you're closer solution, assuming can require snow leopard. instead of asking nsimage tiff representation, ask cgimage.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -