initWithFocusedViewRect problem - corrected
initWithFocusedViewRect problem - corrected
- Subject: initWithFocusedViewRect problem - corrected
- From: Andrei Kolev <email@hidden>
- Date: Mon, 23 Jul 2001 20:26:19 +0300
Please ignore the previous message - the initWithFocusedViewRect: is not
on the line it should be!
Hello everybody!
In one of my methods which returns NSBitmapImageRep I have:
//...some unimportant stuff goes here, assume x, y, , tempWindow,
backgroundColor, backgroundRect are defined, theImage is passed to the
method as an argument
[[tempWindow contentView] lockFocus];
[backgroundColor set];
[NSBezierPath fillRect:backgroundRect];
[theImage compositeToPoint:NSMakePoint(x, y)
operation:NSCompositeSourceOver];
//...some not very complex NSBezierPath operations here
newBitmapImageRep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:backgroundRect];
[[tempWindow contentView] unlockFocus];
return([newBitmapImageRep autorelease]);
After calling the method (assuming the returned NSBitmapImageRep is
newBitmapImageRep, somePath, fileProperties and filePermissions are
defined) I have :
noErr=[[NSFileManager defaultManager] createFileAtPath:somePath contents:
[newBitmapImageRep
representationUsingType:NSJPEGFileType
properties:fileProperties]
attributes:filePermissions];
In general, this works fine. But in some rare cases the saved image (the
returned NSBitmapImageRep) is corrupted. It seems that the
NSBitmapImageRep is initialized before the drawing is finished - I have
1/3, 1/2, 3/4 (some portion) of the image and/or the background drawn
and the rest is the window background (the JPEG file is valid, the image
stored in it is partially drawn). I think I have to synchronize the
off-screen drawing and the initWithFocusedViewRect method. How to do
that?
Thank you in advance for any suggestions and ideas you could share.
Best Regards,
Andrei