允许用户在UIImagePickerController中以纵向视图尺寸拍摄图片

时间:2013-07-06 11:40:08

标签: iphone ios ios6

我的应用程序仅在纵向视图中。

我从相机拍摄图像并将其显示在UIImagePickerController的图像视图中。 现在,如果我旋转设备,则会在横向视图中拍摄照片,图像尺寸会从1936*2592(即用于纵向)更改为2592*1936

现在我想在纵向视图中显示与默认相机完全相同的图像。

请告诉我该怎么办?
或者是否可以仅将UIImagePicker锁定为肖像?

1 个答案:

答案 0 :(得分:0)

您可以调整图片大小

- (UIImage *)imageByScalingToSize:(CGSize)targetSize
{

    UIImage *sourceImage = yourImage;
    UIImage *newImage = nil;

    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;

    //   CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;

    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);

    // this is actually the interesting part:

    UIGraphicsBeginImageContext(targetSize);

    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;

    [sourceImage drawInRect:thumbnailRect];

    newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    if(newImage == nil) NSLog(@"could not scale image");


    return newImage ;
}