Re: Cocoa copy bits was: (no subject)
Re: Cocoa copy bits was: (no subject)
- Subject: Re: Cocoa copy bits was: (no subject)
- From: publiclook <email@hidden>
- Date: Fri, 25 Jul 2003 09:43:09 -0400
NSImage *workImage = [[NSImage alloc]
initWithSize:NSMakeSize(size, size)];
[workImage lockFocus];
[seedImage compositeToPoint:NSZeroPoint fromRect:offScreenRect
operation:NSCompositeCopy];
[workImage unlockFocus];
To scale an image just scale the coordinate system.
Remember that in Cocoa, all windows are double buffered. Some of this
type of work may not be needed.
For information:
1) You don't usually need to mess with image reps directly unless you
need to control bit depth and similar issues.
2) If you are using image reps directly, you don't need to use NSImage
at all. NSImage is a collection of image reps and wrapper logic
intended to make using images simple and flexible. If you need complex
interaction, just bypass the NSImage class entirely.
On Friday, July 25, 2003, at 05:17 AM, John Brewer wrote:
Anyone know how to do a simple CopyBits in Cocoa? I'm trying:
workImage = [[NSImage alloc] initWithSize:NSMakeSize(size, size)];
[workImage setCacheMode: NSImageCacheNever];
workImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL
pixelsWide: size
pixelsHigh: size
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: rowBytes
bitsPerPixel: 0]
autorelease];
[workImage addRepresentation: workImageRep];
NSLog([[workImage representations] description]);
[workImage lockFocusOnRepresentation: workImageRep];
[seedImage compositeToPoint: NSZeroPoint fromRect: offScreenRect
operation: NSCompositeCopy];
[workImage unlockFocus];
NSLog([[workImage representations] description]);
(seedImage's NSImageRep is an NSBitmapImageRep, in case that matters).
The first NSLog indicates that workImage's sole NSImageRep is an
NSBitmapImageRep. The second NSLog indicates that workImage's sole
NSImageRep is an NSCachedImageRep, from which I can't extract the
image data, which was the whole point of this exercise in the first
place.
Basically, I'd like way to say, "copy this rectangle in seedImage to
this rectangle in workImage". In this case, the rectangles are the
same size, but I'd hope there's also a way that works like QuickDraw's
CopyBits, which could do arbitrary scaling.
Thanks,
--
John Brewer
Jera Design
Extreme Programming FAQ: http://www.jera.com/techinfo/xpfaq.html
_______________________________________________
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.
_______________________________________________
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.
References: | |
| >(no subject) (From: John Brewer <email@hidden>) |