• 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
Re: How do I draw a CGImage (30 sq px PNG) upon a host (larger) CGImage <PNG> Image at a specific coordinate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I draw a CGImage (30 sq px PNG) upon a host (larger) CGImage <PNG> Image at a specific coordinate?


  • Subject: Re: How do I draw a CGImage (30 sq px PNG) upon a host (larger) CGImage <PNG> Image at a specific coordinate?
  • From: Scott Thompson <email@hidden>
  • Date: Sat, 27 Jun 2009 09:11:58 -0500


On Jun 26, 2009, at 2:25 PM, Frederick C. Lee wrote:

Environment: iPhone OS 3.0

Greetings:
I would like to place one or more reference icons (png) upon a host image (png) {Like a street map with legends, landmarks, etc.}.
I'm working with Quartz so I'm using pre-loaded CGImages via UIImage.CGImage, for both the map/layout and the icons.

Use UIGraphicsBeginImageContext to create a graphics context attached to a third image. Draw the first (Background image) using UIImage's drawAtPoint: or drawInRect: methods, then draw the second (reference icon) image. UIGraphicsGetImageFromCurrentImageContext will give you the final image after which you can close down the context using UIGraphicsEndImageContext.



Here's some pseudo-code (typed into mail so it might not compile)

UIGraphicsBeginImageContext( hostImageSize )
[hostImage drawInRect: CGRectMake(0, 0, hostImageSize.width, hostImageSize.height)]
[refIcon drawAtPoint: <some well calculated point here>]
UIImage *combinedImage = UIGraphicsGetImageFroCurrentImageContext();
UIGraphicsEndImageContex()


Questions:
1) Should destination context be the host-image context vs UIGraphicsGetCurrentContext() ?
If so, how do you get a drawing context from a PNG image?

I would draw into an entirely new context, as above, preserving the background image.


3) Should I make the source PNG image (the ref icon) a CGLayer object?

Only if you plan to draw the same icon over and over on the map. In that case you would create the image context and grab the current context as above, then create your CGLayer passing the new context to CGLayer. Draw your reference icon into the layer, and draw the layer as many times as you care to to draw the reference icon.


I would very carefully check the performance of such an operation, however, the drawing environment on the phone is quite a bit simpler than the drawing environment on a desktop machine. The speed advantage of a CGLayer may not be as advantageous.

4) Can I work with a different scale (say, 4x) to more-accurately place the icons upon the host?


Quartz 2D uses floating point coordinates. You have the full accuracy of that type to place the image at sub-pixel resolutions. I can't see why you would need to scale the host image to place the reference icon accurately.

Scott

_______________________________________________

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


References: 
 >How do I draw a CGImage (30 sq px PNG) upon a host (larger) CGImage <PNG> Image at a specific coordinate? (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: GC pros and cons
  • Next by Date: Re: GC pros and cons
  • Previous by thread: How do I draw a CGImage (30 sq px PNG) upon a host (larger) CGImage <PNG> Image at a specific coordinate?
  • Next by thread: displaying natural language time intervals
  • Index(es):
    • Date
    • Thread