How to Create Thumbnail of UIImage – XCode iOS

Use the following Code to Create Thumbnail of UIImage Object –

1
2
3
4
5
6
UIImage *originalImage = ...;
CGSize destinationSize = ...;
UIGraphicsBeginImageContext(destinationSize);
[originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Replace the originalImage object with your original image of which you want to create the thumbnail. The new version of the same image ie. the thumbnail will be the newImage object. The original image will not be modified.

You can now save the thumbnail image to documents directory of the iOS Device. Check the following article Save and Load UIImage in Documents Directory on iPhone.

Namit Gupta

Technical Lead iOS @ONEChampionship | Ex-SDE2 @ Halodoc, Ex-iOS Lead @ Vokal. ❤️ Swift, designing pixel-perfect UI and writing clean code. Check my portfolio here.

Leave a Reply