Re: Help with offscreen drawing
Re: Help with offscreen drawing
- Subject: Re: Help with offscreen drawing
- From: Jan Van Boghout <email@hidden>
- Date: Thu, 15 Aug 2002 11:16:48 +0200
Why do you use an offscreen window for that? I've only just started
exploring this myself, but I just use something like the following:
NSImage *anImage;
[anImage lockFocus];
//do NSBezierpath stuff here
[anImage unlockFocus];
Works for me, I haven't encountered any problems with it.
Jan
Keith Renz heeft op donderdag, 15 aug 2002 om 02:01 (Europe/Brussels)
het volgende geschreven:
I am trying to draw offscreen, convert it to a pdf image and use the
image in
various locations including a table column's image cell. Here's what
I'm
doing...
In an NSWindowController subclass method:
- (void)windowDidLoad
{
NSRect rect;
NSWindow *offWindow;
NSView *view;
NSBezierPath *path;
NSColor *color;
NSData *data;
// Create an offscreen window.
rect = NSMakeRect(0, 0, 100, 50);
offWindow = [[NSWindow alloc] initWithContentRect: rect styleMask:
NSBorderlessWindowMask backing: NSBackingStoreRetained defer: NO];
// Get the offscreen window's content view.
view = [offWindow contentView];
// Draw an oval into the view.
[view lockFocus];
rect = [view frame];
rect = NSInsetRect(rect, 3, 3);
path = [NSBezierPath bezierPathWithOvalInRect: rect];
[path setLineWidth: 3];
color = [NSColor colorWithCalibratedRed: 1.0 green: 0.5 blue: 0.5
alpha:
0.5];
[color set];
[path fill];
color = [NSColor colorWithCalibratedRed: 1.0 green: 0.125 blue:
0.125
alpha: 0.5];
[color set];
[path stroke];
[view unlockFocus];
// Create the test image.
data = [view dataWithPDFInsideRect: [view frame]];
testImage = [[NSImage alloc] initWithData: data];
// Clean up.
[offWindow release];
}
Then in an NSView subclass method:
- (void)drawRect:(NSRect)rect
{
MBPLinesController *controller;
NSImage *image;
NSPoint point;
// Get a reference to the test image.
controller = [[self window] windowController];
image = [controller testImage];
// Draw the test image.
point = NSMakePoint(0, 0);
[image compositeToPoint: point operation: NSCompositeSourceOver
fraction:
0.5];
}
It's not working. testImage exists and is the correct size, but I
can't seem
to get it to draw into an NSView. My guess is that nothing is being
drawn
into the offscreen view. If I do the exact same steps using an onscreen
window, all works well.
Thanks,
Keith
_______________________________________________
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.