如何设置使用UIImagePickerController拍摄的照片进行查看/修改为自定义UIViewController? [英] How to set photo taken with UIImagePickerController to be viewed/modified into a custom UIViewController?

查看:91
本文介绍了如何设置使用UIImagePickerController拍摄的照片进行查看/修改为自定义UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用默认的 UIImagePickerController ,并且在拍摄照片后立即显示以下默认屏幕:

I am currently using the default UIImagePickerController, and immediately after a picture is taken, the following default screen is shown:

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

My question is, how would I be able to use my own custom UIViewController to view the resultant image (and therefore bypass this confirmation screen ).
Please note that am not interested in using a custom overlay for the UIImagePicker with custom camera controls or images from photo gallery, but rather just to skip this screen and assume that the photo taken is what the user would have liked.

谢谢!

推荐答案

尝试使用此代码将结果图像维持在相同的大小:

Try this code to maintain your resultant image in same size:

首先创建 IBOutlet for UIImageview

-(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, 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;
}

这篇关于如何设置使用UIImagePickerController拍摄的照片进行查看/修改为自定义UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆