« Back to blog

Adding and Saving a Border Around a UIImage with Core Graphics

I recently had to place a border around an image of unknown size and save it back as an image. Here is how:

Start with a UIImage:

No_border

Run it through this method:

You will get back a UIImage with a border. Simple.

Border

Obviously, you will need to adjust the border percentage and color for your own application.

| Viewed
times | Favorited 0 times

2 Comments

Nov 06, 2011
Eran Talmor said...
Thanks for this, works great.

Just don't forget to add this:

free(data);

Otherwise it leaks. Cheers

Nov 10, 2011
Ganesh said...
Thank you so much for the code!, you have saved some of my time, thank you

Leave a comment...