Still Offscreen Drawing Problems ...
Still Offscreen Drawing Problems ...
- Subject: Still Offscreen Drawing Problems ...
- From: Manfred Lippert <email@hidden>
- Date: Thu, 07 Feb 2002 13:21:42 +0100
Hi,
it's still me figuring out how I can get offscreen drawing to work. Your
tipps with NSImage/NSBitmapImageRep seemed to point in the right direction,
but I had no success yet.
That's what I need:
1.) I want a RGBA bitmap that I can manipulate myself (setting RGBA values,
e.g. for filtering effects etc.)
2.) I want to be able to draw into this bitmap, especially an
NSAttributedString.
3.) I want to be able to draw the whole bitmap into an NSView.
That's what I tried to do, but it does not work:
For testing reasons I put this code into the drawRect Method if an NSView:
I marked the above things (1., 2., 3.) in the code below:
- (void) drawRect:(NSRect)rect {
static BOOL first_draw = TRUE;
if (first_draw) {
NSImage *offscreenImage = [[NSImage alloc] initWithSize:size];
uint8_t *offscreenData = malloc(width * 4 * height);
NSBitmapImageRep *offscreenBitmap =
[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:&offscreenData
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:width * 4
bitsPerPixel:32
];
memset(offscreenData, 0x5555, width * 4 * height); // 1.)
[offscreenImage addRepresentation:offscreenBitmap];
[offscreenImage lockFocus];
[attributedString drawAtPoint:NSZeroPoint]; // 2.)
[offscreenImage unlockFocus];
[offscreenImage compositeToPoint:NSZeroPoint
operation:NSCompositeSourceOver]; // 3.)
first_draw = FALSE;
}
}
The result is: _Nothing_. There isn't drawn anything in my NSView.
What am I doing wrong?
If I check the offscreenData after 2.) there has nothing changed.
So I think 2.) does not work.
But if I draw the attributesString in the NSView (commenting out the
lockFocus/unlockFocus lines), it is drawn. It is not drawn in my NSImage
only.
Point 3.) does not work either. There is nothing displayed in my NSView.
size, width, height etc. are set to the right values. I left out the code
for calculating these values in this example, but I checked that in the
debugger. witdh and height are both about 200 Pixels, and size has the same
values (as float) in it, but might be a little less ( < 1 Pixel difference).
Please help!
Thank you,
Mani
_______________________________________________
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.