I need to composite/tile about 20 images in a 4x5 grid to one image. Currently I do:
NSImage* canvas = [[[NSImage alloc] initWithSize:NSMakeSize(canvasWide, canvasHigh)] autorelease]; [canvas lockFocus]; Loop { ... Get the CGImage which comes from an AVAssetImageGenerator frameImage = [[[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize] autorelease]; ... Determine x/y positions [frameImage drawInRect:NSMakeRect(xPos, yPos, tileWidth, tileHeight) fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; } NSBitmapImageRep *imageRep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, [canvas size].width, [canvas size].height)] autorelease] ; [canvas unlockFocus]; // convert to jpeg NSDictionary* imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.5] forKey:NSImageCompressionFactor]; NSData* imageData = [imageRep representationUsingType:NSJPEGFileType properties:imageProps]; Profiling this shows lots of time (90%) is spent in drawInRect and it takes about 2 seconds to run. Is there a better way to do this that is faster? Maybe keep everything in CG and only convert to NSImage at the end? Not sure how to do this. Note that the cgImage is bigger that the frameImage but they have similar aspect ratios. Thoughts? Trygve _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com