render to 128x128 image
render to 128x128 image
- Subject: render to 128x128 image
- From: Jake <email@hidden>
- Date: Sun, 11 Nov 2001 20:54:46 -0500 (EST)
Trying to render some stuff into an Icon with the following code:
const int width = 128;
const int height = 128;
int i;
NSImage *buf;
NSBitmapImageRep *bufrep;
unsigned char *d[5];
buf = [[NSImage allocWithZone:[self zone]]
initWithSize:NSMakeSize(width, height)];
[buf retain];
bufrep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide: width
pixelsHigh: height
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: YES
colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: 0
bitsPerPixel: 32];
[bufrep retain];
[buf addRepresentation:bufrep];
[bufrep getBitmapDataPlanes:d];
[buf lockFocus];
for (i = 0; i < 256 * 255; i++)
{
d[0][i] = 255;
d[1][i] = 0;
d[2][i] = 0;
d[3][i] = 255;
}
for (i = 256 * 255; i < 256*256; i++)
{
d[0][i] = 0;
d[1][i] = 255;
d[2][i] = 0;
d[3][i] = 255;
}
[bufrep draw];
[buf unlockFocus];
is that the right way to do it?
also the above drawing routine seems to finally cover the entire 128x128
area with agreen segment at the end. This is something I don't quite get.
If I understand correctly "getBitmapDataPlanes" in this case suppose to
return me 4 arrays. Each of 128x128 unsigned char in length representing
the r,g,b,a. So if that is the case, how come I need to draw as far as to
256 x 256 in the loop to cover the entire image?
Thanks.
jake