Gaby Fitcal
Gaby Fitcal

Reputation: 1944

Set maximum image resolution for PickerController?

I want take a image with a fixed resolution. The user need to be forced for crop the image. I need a square image.

I'am using next code and it just crop by width screen resolution.

self.imagepicker = [[UIImagePickerController alloc]init];
self.imagepicker.delegate = self;
self.imagepicker.allowsEditing=YES;
self.imagepicker.preferredContentSize = CGSizeMake(200, 200);

self.imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:self.imagepicker animated:YES completion:nil];

Upvotes: 0

Views: 248

Answers (2)

Ilesh P
Ilesh P

Reputation: 4036

If you want to done after selecting image please try this code for crop image in center

- (UIImage *)squareImageFromImage:(UIImage *)image scaledToSize:(CGFloat)newSize1
{
    CGAffineTransform scaleTransform;
    CGPoint origin;
    CGFloat newSize;

    if (image.size.width > image.size.height)
    {
        newSize=image.size.height;
        CGFloat scaleRatio = newSize / image.size.height;
        scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
        origin = CGPointMake(-(image.size.width - image.size.height) / 2.0f, 0);
    }
    else
    {
        newSize=image.size.width;
        CGFloat scaleRatio = newSize / image.size.width;
        scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
        origin = CGPointMake(0, -(image.size.height - image.size.width) / 2.0f);
    }

    CGSize size = CGSizeMake(newSize, newSize);
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(size, YES, 0);
    } else {
        UIGraphicsBeginImageContext(size);
    }

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextConcatCTM(context, scaleTransform);

    [image drawAtPoint:origin];

    image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;
}

Its helpful to you. Thanks

Upvotes: 1

jcaron
jcaron

Reputation: 17710

preferredContentSize is not a property of the UIImagePickerController itself, but of any UIViewController, for when it is embedded in a UIPopoverController.

You'll need to present a cropping interface yourself.

Upvotes: 1

Related Questions