• 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: Seeking image manipulation book/site/course recommendations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seeking image manipulation book/site/course recommendations


  • Subject: Re: Seeking image manipulation book/site/course recommendations
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 23 Mar 2016 13:29:25 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sDnc9w1QCT:SMTPCORP

On Mar 23, 2016, at 10:41 , Charles Jenkins <email@hidden> 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@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: 
 >Seeking image manipulation book/site/course recommendations (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Seeking image manipulation book/site/course recommendations
  • Next by Date: Re: IKImageBrowserView bug?
  • Previous by thread: Seeking image manipulation book/site/course recommendations
  • Next by thread: override NSTextField paste behavior
  • Index(es):
    • Date
    • Thread