Resizing Images iPhone SDK
I am working on an iOS App which uses the iDevice Camera to grab images and upload them to a remote server. There is a scenario in which the user can grab a picture using the Camera, select开发者_Python百科 a particular portion of the image using the native camera control and use it. The user also can use the full image without selecting a particular portion.
Now, the thing is that there are two types of devices majorly:
- iPhone / iTouch 2G, 3G, 3GS
- iPhone / iTouch 4
There would be camera image resolution differences as well.
The question is that shall we double the resolution of our required size in order to have an image that can be properly displayed on both the device types or we can have a common size which would work on both? If there can be a common size, what that would be?
I am not sure to clearly understand your question, but if you want to display your image, you can use such code :
UIImage* myImage = [UIImage imageNamed:@"my_image.png"];
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myImageView.image = myImage;
[self.view addSubView:myImageView];
This will display your image full screen. If you run this code on iOS 4, this will adapt to the iPhone 4 resolution automatically.
An image of any size will 'work' on both devices - where it really matters is performance and efficiency. For instance, if you are showing these images in a scrolling table view, you don't want to have the non-retina devices downloading and drawing a huge scaled-down image or your table view will stutter a lot.
It might be best to upload the highest resolution necessary, and then your remote server should produce scaled-down images, which can be provided dynamically based on the needs of the requesting device. This is better than using a common image size for both devices, because you will either be slowing your app down unnecessarily or displaying a pixelated image.
For instance: let's say a user captures a 200x200 image. You want the image (when downloaded) to be displayed in a 50x50 image view. You'll want your remote server to provide a 100 px image for the retina displays, and a 50 px image for the non-retina displays. Each devices should request the appropriate size image for its device resolution. The image view can handle the scaling, and each will look smooth and download speed and app performance should be optimal.
If you want to save even more bandwidth, in the scenario described above you can scale down your image to 100x100 before submitting. Some good tips on this here:
https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more
精彩评论