gpt4 book ai didi

iphone - 使用 UIImagePickerController 以特定分辨率捕获照片

转载 作者:技术小花猫 更新时间:2023-10-29 10:56:35 28 4
gpt4 key购买 nike

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

我们可以在以下品质中进行选择:

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

如果我们使用 AVFoundation,我们可以从 this nice table 中选择分辨率(在标题“捕获静止图像”下)。

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

最佳答案

UIImagepickerController quality用于视频录制(在 UIImagepickerController 属性“videoQuality”中使用)。

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

之后调整它的大小(找到 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;
}

希望这对您有所帮助!

关于iphone - 使用 UIImagePickerController 以特定分辨率捕获照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12258280/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com