title: Two ways to put image into graphics context - which is better?
body: <p>I've noticed examples of two ways to put images into core graphics.  One is much simpler than the other.  So what's the advantage of the second, more sophisticated, approach?  Is it faster?</p>
  
  <p>example 1</p>
  
  <pre><code>UIImage *myImage = [UIImage imageNamed:@"picture.png"];
  CGRect imageRect = CGRectMake(70, 330, 40, 40);
  [myImage drawInRect:imageRect];
  [myImage release];
  </code></pre>
  
  <p>example 2</p>
  
  <pre><code>// Load image from application bundle
  NSString* imageFileName = [[[NSBundle mainBundle] resourcePath]         stringByAppendingPathComponent:@"picture.png"];
  CGDataProviderRef provider = CGDataProviderCreateWithFilename([imageFileName UTF8String]);
  CGImageRef image = CGImageCreateWithPNGDataProvider(provider, NULL, true,      kCGRenderingIntentDefault);
  CGDataProviderRelease(provider);
  
  // Draw image
  CGContextTranslateCTM(context, 70, 370 );
  CGContextScaleCTM(context, 1.0, -1.0);
  CGContextDrawImage(context, CGRectMake(0, 0, 40, 40), image);
  CGImageRelease(image);
  </code></pre>