I have a view who's bounding rectangle has been normalize to make drawing a grid easier. It' bounds is set to ~1x1. Currently I can draw the grid and what ever curve I want just fine. What I am trying to do is draw into a NSImage and render it in the view and cache the image so I can also save the image to disk later. In my test example I am drawing a curve and to see if the curve renders prior to unlockFocus(i.e post the last stroke method) I make a call to:

    NSRect br = [bp controlPointBounds];
NSLog(@"Path Bounding Box: origin.x:%1.5f origin.y:%1.5f size.width:%1.5f size.height:%1.5f", br.origin.x, br.origin.y, br.size.width, br.size.height);

The Output I get is: Path Bounding Box: origin.x:0.00000 origin.y:0.00000 size.width:1.00000 size.height:1.00000. Looks like the path is drawn just fine.

The documents look pretty straight forward but it looks like I am only getting a 1x1 view of my data(i.e. the pixel(s) at 0,0) and losing the scaling factor of the frame. I am assuming the same trick to normalize a view to 1x1 should also work?? Again, if I just draw to the view and not to the image, it all draws perfectly.

This is what I am doing.

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        viewBounds = NSMakeRect(-0.1, -0.1, 1.2, 1.2);
        [self setBounds:viewBounds];
    }
    return self;
}

-(void) setFrameSize:(NSSize)newSize
{
    [super setFrameSize:newSize];
    [self setBounds:viewBounds];
}

- (void)drawRect:(NSRect)dirtyRect
{

// Set the image size to the bounding rect
    NSImage* anImage = [[NSImage alloc] initWithSize:viewBounds];
    [anImage lockFocus];

// Draw a bunch of stuff



// Unlock and draw the image
    [anImage unlockFocus];
    [anImage drawAtPoint:NSMakePoint(0, 0)
                fromRect: NSZeroRect
               operation: NSCompositeSourceOver
                fraction: 1.0];

 [anImage release];  // for now.
}

Thanks people,
-Tony
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to