Mar 11 2010

UIImage resizing

UIImage is a great class, but it has a lot of limitations.

Image resizing is one of them (the lack of). If your looking for a way to re-size UIImages, save your self the agony of copy/pasting the numerous code examples you’ll find through stackoverflow or whatever. I was shocked by the amount of people posting buggy code, for what is actually a relatively simple problem.

I do find it funny that people describe CoreGraphics or Quartz as low level APIs. For a primarily Objective-C coder maybe, but for anyone who has experience with C, it shouldn’t pose much of a burden. Sure CoreGraphics IS lower level than UIImage, but I’d still describe it as a fairly “high level” API, especially when you compare it to OpenGL.

Anyhow, if your looking to re-size UIImages easily, without having to use CoreGraphics or Quartz, I would strongly recommend checking out Trevor’s article over here:

http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

He has written some UIImage categories which will save a lot of time, and more importantly they are well written (and work).