Re: drawing pixels
Re: drawing pixels
- Subject: Re: drawing pixels
- From: Chris Hanson <email@hidden>
- Date: Sun, 21 Mar 2004 15:10:12 -0500
On Mar 21, 2004, at 7:26 AM, Tobias Kl|pfel wrote:
control the data object of an NSBitmapImageRep (I gave up trying to
figure out the format - there has to be an easier way)
With an NSBitmapImageRep, the format is what whatever you want it to be:
NSMutableData *rasterData = [[NSMutableData alloc]
initWithLength:((640 * 4) * 480)];
unsigned char *rasterDataPlanes[1];
rasterDataPlanes[0] = [rasterData mutableBytes];
NSBitmapImageRep *imageRep
= [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:rasterDataPlanes
pixelsWide:640
pixelsHigh:480
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:(640 * 4)
bitsPerPixel:32];
With this, rasterDataPlanes[0] is your raw raster data, stored in row
order, using chunky RGBA 8/8/8/8 pixels. You can manipulate this
information directly, and draw it by setting up a view appropriately
and sending your imageRep -draw. Or you can set it as a representation
for an NSImage, or...
You can also choose to use planar data (each color stored in its own
buffer) by passing YES for the isPlanar: argument, passing an array of
four pointers in for the data planes, and passing appropriate values
for bytesPerRow: and bitsPerPixel:. (Or three if there are only 3
samples per pixel.) This is handy for some algorithms that operate on
different color channels independently. You can even use some non-RGB
color spaces.
-- Chris
--
Chris Hanson <email@hidden>
http://www.livejournal.com/users/chanson/
_______________________________________________
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.