initWithFocusedViewRect problem
initWithFocusedViewRect problem
- Subject: initWithFocusedViewRect problem
- From: Andrei Kolev <email@hidden>
- Date: Mon, 23 Jul 2001 20:21:58 +0300
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];
newBitmapImageRep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:backgroundRect];
//...some not very complex NSBezierPath operations here
[[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