使用UIImagePickerController捕获具有特定分辨率的照片 [英] Capturing photos with specific resolution using the UIImagePickerController

查看:108
本文介绍了使用UIImagePickerController捕获具有特定分辨率的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拍摄A4纸的照片。重要的是,我希望文本可读,但我不希望像2592x1936像素或3264x2448像素这样的分辨率的图像太大。此外,我认为在拍摄后重新缩放照片需要额外的时间,所以我也想避免这种情况。

I would like to take photos of A4 pieces of paper with writing on. Importantly, I want the text to be readable, but I do not want images with resolutions like 2592x1936 pixel or 3264x2448 pixel as that would be too big. Also, I assume that rescaling the photo after capturing takes extra time, so I would like to avoid this too.

我们可以选择以下品质:

We can choose between the following qualities:

UIImagePickerControllerQualityTypeHigh = 0   
UIImagePickerControllerQualityTypeMedium          = 1  default value   
UIImagePickerControllerQualityTypeLow            = 2   
UIImagePickerControllerQualityType640x480         = 3,   
UIImagePickerControllerQualityTypeIFrame1280x720  = 4,   
UIImagePickerControllerQualityTypeIFrame960x540   = 5 

如果我们使用 AVFoundation ,我们可以从这张漂亮的桌子(标题为捕捉静止图像)。

If we were using the AVFoundation, we could choose resolutions from this nice table (under headline "Capturing Still Images").

但是有 UIImagePickerController 的类似表格,例如说iPhone 3gs上的 UIImagePickerControllerQualityTypeHigh 等于1920x1080?

But is there a similar table for UIImagePickerController, which for example says that UIImagePickerControllerQualityTypeHigh equals 1920x1080 on iPhone 3gs?

推荐答案

UIImagepickerController质量用于视频录制(用于UIImagepickerController属性videoQuality)。

UIImagepickerController quality is used for video recording (used in UIImagepickerController property "videoQuality").

我想如果你想指定确切的照片分辨率应该是什么,你应该使用AV Foundation框架而不是UIImagepickerController。或者如你所说,之后转换图片。

I guess that if you want to specify what the exact photo resolution should be, you should use the AV Foundation framework instead of the UIImagepickerController. Or as you said, convert the picture afterwards.

之后调整大小(找到这里):

To resize it afterwards (found here):

//  ==============================================================
//  resizedImage
//  ==============================================================
// Return a scaled down copy of the image.  

UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)
{
    CGImageRef          imageRef = [inImage CGImage];
    CGImageAlphaInfo    alphaInfo = CGImageGetAlphaInfo(imageRef);

    // There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
    // see Supported Pixel Formats in the Quartz 2D Programming Guide
    // Creating a Bitmap Graphics Context section
    // only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
    // and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
    // The images on input here are likely to be png or jpeg files
    if (alphaInfo == kCGImageAlphaNone)
        alphaInfo = kCGImageAlphaNoneSkipLast;

    // Build a bitmap context that's the size of the thumbRect
    CGContextRef bitmap = CGBitmapContextCreate(
                NULL,
                thumbRect.size.width,       // width
                thumbRect.size.height,      // height
                CGImageGetBitsPerComponent(imageRef),   // really needs to always be 8
                4 * thumbRect.size.width,   // rowbytes
                CGImageGetColorSpace(imageRef),
                alphaInfo
        );

    // Draw into the context, this scales the image
    CGContextDrawImage(bitmap, thumbRect, imageRef);

    // Get an image from the context and a UIImage
    CGImageRef  ref = CGBitmapContextCreateImage(bitmap);
    UIImage*    result = [UIImage imageWithCGImage:ref];

    CGContextRelease(bitmap);   // ok if NULL
    CGImageRelease(ref);

    return result;
}

希望这会有所帮助!

这篇关于使用UIImagePickerController捕获具有特定分辨率的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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