• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Help with offscreen drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help with offscreen drawing


  • Subject: Help with offscreen drawing
  • From: Keith Renz <email@hidden>
  • Date: Wed, 14 Aug 2002 20:01:38 -0400

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.

  • Prev by Date: Classes in bundles
  • Next by Date: Setting a class' action
  • Previous by thread: Re: Classes in bundles
  • Next by thread: Re: Help with offscreen drawing
  • Index(es):
    • Date
    • Thread