1

I'm getting an edited image from UIImagePickerController. On retina iOS devices, the image returned is 640x640, but on non-retina iOS devices, the image returned is only 320x320.

How do I get 640x640 from the controller on non-retina devices without manually upscaling? I need the sizes to be constant regardless of the screen because I am uploading it.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = info[UIImagePickerControllerEditedImage];

    //image.size is 320x320 points on both retina and non-retina devices.
    //How do I get 640x640 *pixels* for non-retina devices without upscaling?
}
iPatel
  • 46,010
  • 16
  • 115
  • 137
1actobacillus
  • 408
  • 4
  • 12

1 Answers1

1

I am not sure but may be without resize of image, it is not possible to get image for retina and non-retina automatically.

So, You need to resize you image by following code;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];


   UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
   img = [self resizeImage:img];

  // here you got, img = 640x640 or 320x320 base on you device;

}

Code of resizeImage,

- (UIImage*)resizeImage:(UIImage*)image
{ 
    CGSize newSize = nil;

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]
     && [[UIScreen mainScreen] scale] == 2.0) {
         // Retina
         newSize = CGSizeMake(640, 640); // Here you need to set size as you want;
    } else {
          // Not Retina
        newSize = CGSizeMake(320, 320); // Here you need to set size as you want;
     }

    UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want

    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}
iPatel
  • 46,010
  • 16
  • 115
  • 137