ios – 如何设置使用UIImagePickerController拍摄的照片进行查看/修改为自定义UIViewController?

前端之家收集整理的这篇文章主要介绍了ios – 如何设置使用UIImagePickerController拍摄的照片进行查看/修改为自定义UIViewController?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在使用默认的UI ImagePickerController,并在拍摄照片后立即显示以下默认屏幕:

我的问题是,我如何能够使用自己的自定义UIViewController来查看结果图像(因此绕过此确认屏幕).
请注意,我不想使用自定义叠加层为自定义相机控件或照片库中的图像使用UIImagePicker,而只是跳过此屏幕并假设拍摄的照片是用户喜欢的.

谢谢!

解决方法

尝试使用此代码将结果图像保持为相同大小:

首先为UIImageview创建IBOutlet.

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = info[UIImagePickerControllerMediaType];

    [self dismissViewControllerAnimated:YES completion:nil];


    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        OriginalImage=info[UIImagePickerControllerOriginalImage];
        image = info[UIImagePickerControllerOriginalImage];
//----------
            imageview.image = image; // additional method
            [self resizeImage];


//---------
        if (_newMedia)
            UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);

    }
    else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
    {
        // Code here to support video if enabled
    }

}



//---- Resize the original image ----------------------
-(void)resizeImage
{

        UIImage *resizeImage = imageview.image;

        float width = 320;
        float height = 320;

        CGSize newSize = CGSizeMake(320,320);
        UIGraphicsBeginImageContextWithOptions(newSize,NO,0.0);
        CGRect rect = CGRectMake(0,width,height);

        float widthRatio = resizeImage.size.width / width;
        float heightRatio = resizeImage.size.height / height;
        float divisor = widthRatio > heightRatio ? widthRatio : heightRatio;

        width = resizeImage.size.width / divisor;
        height = resizeImage.size.height / divisor;

        rect.size.width  = width;
        rect.size.height = height;

        //indent in case of width or height difference
        float offset = (width - height) / 2;
        if (offset > 0) {
            rect.origin.y = offset;
        }
        else {
            rect.origin.x = -offset;
        }

        [resizeImage drawInRect: rect];

        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

    imageview.image = smallImage;
    imageview.contentMode = UIViewContentModeScaleAspectFit;
}
原文链接:https://www.f2er.com/iOS/334409.html

猜你在找的iOS相关文章