Does lockFocus (NSImage) within another context cause to drop transform info?
Does lockFocus (NSImage) within another context cause to drop transform info?
- Subject: Does lockFocus (NSImage) within another context cause to drop transform info?
- From: "Lukhnos D. Liu" <email@hidden>
- Date: Wed, 7 Mar 2007 06:14:03 +0800
Hi,
I have a windowless application that is responsible to generate a PDF
file by drawing objects first to an NSView object and getting the PDF
content using -dataWithPDFInsideRect:.
Everything worked fine until lately I decided to perform image resizing
when the program is into the drawing. Because of the design (the PDF
may contain a number of images, fetched on the spot from different
sources), the fetching and resizing of the images can't be done
anywhere else than during the drawing, that is when the current
graphics context is within the NSView in question.
I have found, however, that creating an NSImage and performing lockFocus
during the phase caused the transformation information to drop. The
pseudo code below illustrates the problem:
@implementation MyPDFGeneratorView
- (void)drawRect:(NSRect)aRect
{
// get some transformaton objects and apply it
NSAffineTransform *nsat = [self getTransformInfo];
[nsat concat];
// start drawing objects
[self drawObject1];
[self drawObject2];
// fetch an NSImage object, create another one, lock focus,
draw
// within the new object to resize, then draw onto the view
NSImage *origImg = [self getImage];
NSImage *newImg = [[NSImage alloc] initWithSize:newSize];
// == TROUBLE BEGINS
// N.B.: saving/restoring graphics state doesn't work here
[newImg lockFocus];
[origImg drawAtPoint:... fromRect:... operation:...
fraction: ...];
[newImg unlockFocus];
// == TROUBLE ENDS
// newImg drawn with no transformation honored
[newImg drawAtPoint:... fromRect:... operation:...
fraction:...];
}
I have tried to put the image resizing part into another thread, but
that didn't work either (and actually made the origImg drawn onto
the view [cf. the TROUBLE part above], not the newImg, which was really
bizarre).
Did I miss something here? I mean in principle creating a new graphics
context within an existing context should be fine, or? Or is there
any way to save the current transformation information, so when the
newImg unlocks, I can put them back?
Thanks for the help.
d.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden