Re: affine transformation of bitmap images
Re: affine transformation of bitmap images
- Subject: Re: affine transformation of bitmap images
- From: Robert Clair <email@hidden>
- Date: Fri, 4 Mar 2005 09:24:29 -0500
[newImg lockFocus];
NSBitmapImageRep* newBitmapRep =
[[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSMakeRect( 0.0,0.0, [newImg size].width,
[newImg size].height)];
[newImg unlockFocus];
will give you a bitmapRep with the pixels.
I tried that when you first suggested it, and it 'works' (I got an
NSBitmapImageRep) but it no longer draws properly, somehow the
transform
is all screwed up. It works great in the case of an identity
transform.
I'd like to avoid NSImage altogether, but to be able to [bitmapRep
drawInRect:] I need to lock focus on something... but if not NSImage,
what?
Sorry for the delay in getting back to this. I was mixed up -
[newImg setDataRetained: YES];
won't do anything for an NSImage you are drawing into - as Marcel
points out this is always a cached representation. It *will* prevent
an NSImage that has only bitmap representation (say one that you
created by reading an image from a file) from trading its bitmap
representation for a cached representation the first time you draw it.
As for -initWithFocusedViewRect: - the "somehow the transform is all
screwed up" confuses me: you shouldn't be using a transform for this at
all. If you are trying to do everything in one step it should look
something like this:
[newImg lockFocus];
[NSGraphicsContext saveGraphicsState];
[theTransform concat];
NSRect wholeImageRect = NSMakeRect(0.0f, 0.0f, imgSize.width,
imgSize.height);
[origImgRep drawInRect:wholeImageRect];
[NSGraphicsContext restoreGraphicsState];
NSBitmapImageRep* newBitmapRep =
[[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSMakeRect( 0.0,0.0, [newImg size].width,
[newImg size].height)];
[newImg unlockFocus];
The save and restore are important here.
... Bob Clair
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden