UIImage
Image Resizing
iOS Development
Swift Programming
Graphics

Resize UIImage to 200x200pt/px

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Resizing a UIImage sounds simple until points and pixels get mixed together. On iOS, layout uses points, image buffers use pixels, and the final result depends on the renderer scale you choose, so a request for 200x200 needs one more question: do you mean points on screen or exact output pixels in the image data.

Points And Pixels Are Not The Same

A point is a logical layout unit. A pixel is a physical sample in the rendered image. On a 2x display, one point maps to two pixels in each dimension. On a 3x display, one point maps to three.

That means a 200x200 point image rendered at scale 2 becomes 400x400 pixels. If you need an actual 200x200 pixel file, you must control the renderer scale explicitly.

Resize To A Fixed Point Size

If the goal is display size in the UI, UIGraphicsImageRenderer is the easiest modern tool:

swift
1import UIKit
2
3func resizeToPoints(_ image: UIImage, size: CGSize) -> UIImage {
4    let format = UIGraphicsImageRendererFormat()
5    format.scale = image.scale
6
7    let renderer = UIGraphicsImageRenderer(size: size, format: format)
8    return renderer.image { _ in
9        image.draw(in: CGRect(origin: .zero, size: size))
10    }
11}
12
13let resized = resizeToPoints(inputImage, size: CGSize(width: 200, height: 200))

This produces an image that is 200x200 points when drawn with its stored scale. That is usually what you want for UI thumbnails.

Resize To Exact Pixel Dimensions

If you need a file or bitmap that is exactly 200x200 pixels, render with scale 1.0.

swift
1import UIKit
2
3func resizeToPixels(_ image: UIImage, pixelSize: CGSize) -> UIImage {
4    let format = UIGraphicsImageRendererFormat()
5    format.scale = 1.0
6
7    let renderer = UIGraphicsImageRenderer(size: pixelSize, format: format)
8    return renderer.image { _ in
9        image.draw(in: CGRect(origin: .zero, size: pixelSize))
10    }
11}
12
13let pixelExact = resizeToPixels(inputImage, pixelSize: CGSize(width: 200, height: 200))
14print(pixelExact.size)
15print(pixelExact.scale)

With scale 1.0, the point size and pixel size match numerically, so the output buffer is actually 200x200 pixels.

Preserve Aspect Ratio When Needed

A forced 200x200 draw can distort the image if the source is not square. If that is a problem, compute an aspect-fit rectangle inside the target canvas instead of stretching the image to fill the whole area.

That approach is especially common for profile pictures, gallery thumbnails, and export workflows where you want a square target but not a squashed face or logo.

Why UIGraphicsImageRenderer Is Preferred

Older code often uses UIGraphicsBeginImageContextWithOptions, and it still works. UIGraphicsImageRenderer is cleaner, safer, and better aligned with modern UIKit. It handles context setup more predictably and usually reads better in Swift code.

If resizing becomes performance-sensitive, do it off the main thread and cache the result. Large source images can make repeated resizing expensive during scrolling.

If image quality matters, test the resized result with realistic source images instead of only icons or solid colors. Downscaling large photos can reveal blur, alpha-edge artifacts, or aspect-ratio mistakes that are easy to miss with small sample assets.

Common Pitfalls

One common mistake is asking for 200x200 without deciding whether that means points or pixels. The code can be correct and still produce the wrong asset size if the scale assumption is wrong.

Another mistake is always drawing into a fixed square and forgetting aspect ratio. That creates stretched results even though the resize technically succeeded.

A third issue is doing expensive image resizing synchronously during table or collection view reuse. That often causes jank and is better handled in background work plus caching.

Summary

  • On iOS, points control layout and pixels control the actual bitmap size.
  • Use UIGraphicsImageRenderer for modern UIImage resizing.
  • Keep the original image scale when you mean 200x200 points in the UI.
  • Use renderer scale 1.0 when you need an exact 200x200 pixel output.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.