Re: affine transformation of bitmap images
Re: affine transformation of bitmap images
- Subject: Re: affine transformation of bitmap images
- From: "Sean McBride" <email@hidden>
- Date: Fri, 25 Feb 2005 11:02:36 -0500
- Organization: Rogue Research
On 2005-02-24 16:29, Frank Midgley said:
>> Again, I have an NSBitmapImageRep and an NSAffineTransform, and I want
>> an
>> NSBitmapImageRep of the post-transformed image.
>
>When you create the NSImage also create an NSBitmapImageRep with the
>desired settings and add it to the image. Then call
>-lockFocusOnRepresentation: instead of calling -lockFocus.
That seems to also result in an NSCachedImageRep, surprisingly! My code
is as follows, is this what you meant?
// this is the starting image rep
NSBitmapImageRep* origImgRep = [theSP imageRep];
NSSize imgSize = [origImgRep size];
NSImage* newImg = [[NSImage alloc] initWithSize:imgSize];
NSBitmapImageRep* freshImageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:imgSize.width
pixelsHigh:imgSize.height
bitsPerSample:[origImgRep bitsPerSample]
samplesPerPixel:[origImgRep samplesPerPixel]
hasAlpha:[origImgRep hasAlpha]
isPlanar:[origImgRep isPlanar]
colorSpaceName:[origImgRep colorSpaceName]
bytesPerRow:[origImgRep bytesPerRow]
bitsPerPixel:[origImgRep bitsPerPixel]];
[newImg addRepresentation:freshImageRep];
[newImg setCacheMode:NSImageCacheNever];
[newImg lockFocusOnRepresentation:freshImageRep];
[theTransform concat];
NSRect wholeImageRect = NSMakeRect(
0.0f, 0.0f, imgSize.width, imgSize.height);
[origImgRep drawInRect:wholeImageRect];
[newImg unlockFocus];
NSArray* reps = [newImg representations];
assert ([reps count] == 1);
NSBitmapImageRep* newImgRep = [reps objectAtIndex:0];
NSLog (@"%@", [newImgRep class]);
The logs shown there is only 1 rep, and its an NSCachedImageRep.
Thanks!
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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