Best way to composite/tile multiple CGImages to one image
Best way to composite/tile multiple CGImages to one image
- Subject: Best way to composite/tile multiple CGImages to one image
- From: Trygve Inda <email@hidden>
- Date: Sat, 08 Mar 2014 03:38:01 +0000
- Thread-topic: Best way to composite/tile multiple CGImages to one image
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 (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