On Mar 23, 2016, at 10:41 , Charles Jenkins <[email protected]> wrote:
> 
> Can anyone recommend a good book or site or video course where I could learn 
> how to do such image manipulation on iOS?

I don’t think you need a book or tutorial. 
‘UIGraphicsGetImageFromCurrentImageContext’ is your friend. I use this general 
purpose Swift method for creating sprites with arbitrary graphics:

> func spriteWithSize (size: CGSize, isFlipped: Bool = true, drawing: CGRect -> 
> Void) -> SKSpriteNode
> {
>       let contextRect = CGRect (x: 0, y: 0, width: size.width + 2, height: 
> size.height + 2)
>       
>       //      Create a drawing context
>       
>       UIGraphicsBeginImageContextWithOptions (contextRect.size, false, 0)
>       let context = UIGraphicsGetCurrentContext ()!
>       
>       //      Flip the context if necessary
>       
>       if isFlipped
>       {
>               CGContextTranslateCTM (context, 0, contextRect.height)
>               CGContextScaleCTM (context, 1, -1)
>       }
>       
>       //      Invoke the drawing handler
>       
>       drawing (contextRect.insetBy (dx: 1, dy: 1))
>       
>       //      Create the texture
>       
>       let contextImage = UIGraphicsGetImageFromCurrentImageContext ()
>       UIGraphicsEndImageContext ()
>       
>       let texture = SKTexture (image: contextImage)
>       
>       //      Create the sprite
>       
>       return SKSpriteNode (texture: texture, size: contextRect.size)
> }

and it’s used something like this:

> func createImageNode (size: CGSize)
> {
>       let isFlipped = false // for iOS
>       let imageNode = spriteWithSize (size, isFlipped: isFlipped)
>       {
>               drawingRect in
>               
>               //      Clip drawing to a circle
>               
>               UIBezierPath (ovalInRect: drawingRect).addClip ()
>               
>               //      Draw the image
>               
>               let image = UIImage (named: "…")!
>               let drawRect = CGRect (…)
>               
>               image.drawInRect (drawRect)
>       }
>       …
> }

It’s fairly easily translatable into Obj-C if you need that instead.

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to