NSImage lock/unlock slow
NSImage lock/unlock slow
- Subject: NSImage lock/unlock slow
- From: email@hidden
- Date: Sun, 2 Dec 2007 02:16:33 +0100
Hi
I am trying to get an idea of what is fast efficient and so on.
In my case the origin is a NSBitmapImage that I want cutout a portion
from and scale that portion into a new NSBitmapImage.
for (int i = 0; i < 10000; i++) {
// Create a NSImage from NSBitmapImageRep
NSImage *sourceImage = [NSImage alloc];
[sourceImage addRepresentation:image];
[sourceImage setFlipped:true];
// Create a new NSImage
NSRect targetRect = NSMakeRect(0, 0, 20, 20);
NSImage *targetImage = [[NSImage alloc] initWithSize: targetRect.size];
[targetImage setFlipped:true];
[targetImage lockFocus];
// Draw a part from source into target and stretch/shrink
[sourceImage drawInRect:targetRect fromRect:NSMakeRect(371, 179, 10,
10) operation:NSCompositeCopy fraction:1.0];
// Create a NSBitmapImageRep from locked NSImage
NSBitmapImageRep *targetRep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect: NSMakeRect(0, 0, 20, 20)];
[targetImage unlockFocus];
[targetImage release];
[sourceImage release];
}
When running this code over and over again. approx 50% of the time is
spent in lock/unlock and the other 50% in the drawInRect command.
I am a bit demotivated from the fact that the focus command is so
expensive.
To my knowledge there is no way to get around this?????
THX
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden