我在iOS 4.1中使用新的ImageIO框架.我使用以下代码成功检索exif元数据:
CFDictionaryRef metadataDict = CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary , NULL);
Run Code Online (Sandbox Code Playgroud)
阅读它,它似乎是有效的.保存图像有效,但图像中从不存在任何exif数据.
CGImageDestinationRef myImageDest = CGImageDestinationCreateWithURL((CFURLRef) docurl, kUTTypeJPEG, 1, NULL);
// Add the image to the destination using previously saved options.
CGImageDestinationAddImage(myImageDest, iref, NULL);
//add back exif
NSDictionary *props = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:.1], kCGImageDestinationLossyCompressionQuality,
metadataDict, kCGImagePropertyExifDictionary, //the exif metadata
nil];
//kCGImagePropertyExifAuxDictionary
CGImageDestinationSetProperties(myImageDest, (CFDictionaryRef) props);
// Finalize the image destination.
bool status = CGImageDestinationFinalize(myImageDest);
Run Code Online (Sandbox Code Playgroud) 基本任务:更新与UIImage关联的元数据的EXIF方向属性.我的问题是我不知道所有EXIF信息中的orientation属性.
复杂的背景:我正在改变返回的图像的方向,imagePickerController:didFinishPickingMediaWithInfo:所以我想我还需要在保存图像之前更新metaData writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary *)metadata.
换句话说,除非我更改它,否则metaData将包含旧/初始方向,因此是错误的.我改变方向的原因是因为它在我运行Core Image面部检测程序时不停地绊倒我.使用前置摄像头在人像模式下使用iPhone(设备)拍照时,方向为UIImageOrientationRight(3).如果我重写图像使方向为UIImageOrientationUp(0),我会得到良好的面部检测结果.作为参考,下面是重写图像的例程.
整个相机定位的事情我觉得非常混乱,我似乎正在深入挖掘所有这一切的代码洞.我看了帖子(这里,这里和这里.根据这篇文章(/sf/answers/264683471/):
"相机实际上是风景原生的,所以当你拍摄风景照片时,你可以向上或向下拍摄,当你拍摄照片时,你可以向左或向右拍摄(取决于你握住设备的方式)."
......这完全令人困惑.如果以上情况属实,我认为我应该使用前置摄像头UIImageOrientationLeftMirrored或UIImageOrientationRightMirrored使用前置摄像头.而这一切都无法解释为什么CIDetector选择器返回的原始图像失败了.
我正在接近这个屁股,但我似乎无法面向...
-(UIImage *)normalizedImage:(UIImage *) thisImage
{
if (thisImage.imageOrientation == UIImageOrientationUp) return thisImage;
UIGraphicsBeginImageContextWithOptions(thisImage.size, NO, thisImage.scale);
[thisImage drawInRect:(CGRect){0, 0, thisImage.size}];
UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return normalizedImage;
}
Run Code Online (Sandbox Code Playgroud) 我试图找出如何转换CGPoint返回的结果CIFaceFeature,以便用它们绘制CALayer.以前我已经将我的图像标准化为0旋转以使事情变得更容易,但这会导致使用横向模式下的设备拍摄的图像出现问题.
我一直在这方面工作一段时间没有成功,我不确定我对任务的理解是否不正确,或者我的方法是否不正确,或两者兼而有之.这是我认为正确的:

根据该CIDetector featuresInImage:options:方法的文档
A dictionary that specifies the orientation of the image. The detection is
adjusted to account for the image orientation but the coordinates in the
returned feature objects are based on those of the image.
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,我试图旋转CGPoint,以便通过覆盖UIImageView的CAShape图层绘制它.
我正在做什么(......或者我认为我在做......)是将左眼CGPoint平移到视图的中心,旋转90度,然后将点转换回原来的位置.这不正确但我不知道我哪里出错了.我的方法是错误的还是我实施的方式?
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
Run Code Online (Sandbox Code Playgroud)
- leftEyePosition是一个CGPoint
CGAffineTransform transRot = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
float x = self.center.x;
float y = self.center.y;
CGAffineTransform tCenter = CGAffineTransformMakeTranslation(-x, -y);
CGAffineTransform tOffset = CGAffineTransformMakeTranslation(x, y);
leftEyePosition …Run Code Online (Sandbox Code Playgroud)