• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Best way to composite/tile multiple CGImages to one image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Best way to composite/tile multiple CGImages to one image
      • From: Uli Kusterer <email@hidden>
    • Re: Best way to composite/tile multiple CGImages to one image
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: [ANN] WFBezierCombinatorics
  • Next by Date: Re: [ANN] WFBezierCombinatorics
  • Previous by thread: Re: [ANN] WFBezierCombinatorics
  • Next by thread: Re: Best way to composite/tile multiple CGImages to one image
  • Index(es):
    • Date
    • Thread