Re: Seeking image manipulation book/site/course recommendations

2016-03-23 Thread Quincey Morris
On Mar 23, 2016, at 10:41 , Charles Jenkins  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 (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Seeking image manipulation book/site/course recommendations

2016-03-23 Thread Charles Jenkins
I’m developing my first iOS game. I let the player pick photos as images for 
the sprites, and currently use SKCropNodes to combine layers. So each sprite on 
the screen is a crop node.

This works great on my iPhone 6, but performance is just awful on my iPad 2. I 
think I should (a) make sure selected photos are converted so they are no 
larger than what I’ll actually need to display—in other words never scaled down 
for display in the game, and (b) find a way to combine my layers into one image 
and use that to make the SKSpriteNodes, rather than trying to have a bunch of 
crop nodes moving around onscreen at once.

Can anyone recommend a good book or site or video course where I could learn 
how to do such image manipulation on iOS?

-- 

Charles
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com