Re: Rasterizing an NSString to a bitmap
Re: Rasterizing an NSString to a bitmap
- Subject: Re: Rasterizing an NSString to a bitmap
- From: p3consulting <email@hidden>
- Date: Thu, 10 Jun 2004 23:57:42 +0200
>
> Nice, but the problem begin when you modify the NSBitmapImageRep by
>
> accessing directly the pixels
>
> and then try to make a new image from the modified pixels...
>
>
Ahh, that is to be expected. -initWithFocusedViewRect: does not give
>
you access to the backing store, instead it makes a copy. So this is
>
not for incremental drawing onto the backing store, it is for
>
retrieving the result when it is done.
>
>
Well, I cleanup my test code a little bit more and now it works
The correct sequence of ops is
NSImage * myImage = [[NSImage alloc] initWithSize:imageSize] ;
[myImage lockFocus];
// draw whatever you want to get eventually in the bitmap
bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:frame] ;
[myImage unlockFocus];
// manipulate the bytes of the image directly using [bitmapRep
bitmapData]
// draw the representation in another image !
NSImage *newImage = [[NSImage alloc] initWithSize:imageSize] ;
[newImage lockFocus] ;
[bitmapRep drawInRect:NSMakeRect(0.0, 0.0, imageSize.width,
imageSize.height)] ;
[newImage unlockFocus] ;
Of course that's a lot of copy bits behind that but doesn't need the
((graphicsContextInstance) [NSGraphicsContextcurrentContext])->context
trick anymore (at least for that particular purpose)
Pascal Pochet
email@hidden
----------------------------------
PGP
KeyID: 0x208C5DBF
Fingerprint: 9BFB 245C 5BFE 7F1D 64B7 C473 ABB3 4E83 208C 5DBF
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.