Resize UIImage to 200x200pt/px
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
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:
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.
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
UIGraphicsImageRendererfor modernUIImageresizing. - Keep the original image scale when you mean
200x200points in the UI. - Use renderer scale
1.0when you need an exact200x200pixel output.
Related reading
- Resizing UITableView to fit content
- Restrict API requests to only my own mobile app
- Restrict EditText to single line
- Retrieve a Fragment from a ViewPager
- Retrieving Android API version programmatically
- Retrofit 2.0 how to get deserialised error response.body
- Retrofit 2 - Dynamic URL
- Return multiple values from a function in swift
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.