我正在接收AVCaptureSession的UIImage,并将它们设置为UIImageView的。纵向模式设置图像的方向正确,但一旦我使用横向模式,图像设置为顺时针旋转90度。
我做了一些研究,发现我可以通过这种方法使用UIImageOrientation来解决我的问题:
[UIImage imageWithCGImage:cgimageref scale:1 orientation:orientation]但我不明白是怎么做到的。如果我查看所有图像上的UIImageOrientation,则在纵向和横向模式下,该值始终为3 (NSLog(@"%d",UIImageOrientation))。我不明白这对我有什么帮助。我是不是遗漏了什么?
以下是方向代码:
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
self.prevLayer.frame = self.view.bounds;
self.prevLayer.orientation = [[UIDevice currentDevice] orientation];
}shouldAutorotateToInterfaceOrientation返回YES。
发布于 2012-03-30 11:29:35
解决方案需要一些时间才能找到。我必须向AVCaptureConnection添加方向
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections){
for (AVCaptureInputPort *port in [connection inputPorts]){
if ([[port mediaType] isEqual:AVMediaTypeVideo] ){
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}下面这一行是修复方法:
if([videoConnection isVideoOrientationSupported]) {
[videoConnection setVideoOrientation:[[UIDevice currentDevice] orientation]];
}而且所有的图像在任何方向上都能正常工作。
https://stackoverflow.com/questions/9911390
复制相似问题