我想通過UIImagePickerController添加自定義覆蓋視圖,此覆蓋視圖僅支持橫向模式。我只想讓UIImagePickerController在橫向模式下拍照。有什麼辦法可以實現這個...?如何強制UIImagePickerController僅在橫向模式下拍攝圖像....?
0
A
回答
0
我用兩種不同的方法創建了兩個不同的疊加層,調用符合方向的任何一個。
- (IBAction)takePicture:(id)sender {
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
[self portraitDisplayOverlay];
}else{
[self startCameraControllerFromViewController:self usingDelegate:self];
}
}
在人像疊加我設置的UIImagePickerController屬性爲隱藏相機控制
picker.showCameraControls = NO;
此疊加只是指示的用戶使用風景模式,當它傾斜到風景調用適當的覆蓋和瞧。
希望這有助於吉姆。
0
請閱讀蘋果文檔,上面寫着UIImagePickerController類只支持肖像模式:Click Here
注意的是,如果你在風景模式下調用的UIImagePickerController,您的應用程序可以通過蘋果
你必須被拒絕另謀出路,如創建自定義相機使用AVFoundation框架
或
試試這個方法 通過您所拍攝的圖像到一個方法是這樣
// Code from: http://discussions.apple.com/thread.jspa?messageID=7949889
- (UIImage *)scaleAndRotateImage:(UIImage *)image {
int kMaxResolution = 640; // Or whatever
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
if (width > kMaxResolution || height > kMaxResolution) {
CGFloat ratio = width/height;
if (ratio > 1) {
bounds.size.width = kMaxResolution;
bounds.size.height = roundf(bounds.size.width/ratio);
}
else {
bounds.size.height = kMaxResolution;
bounds.size.width = roundf(bounds.size.height * ratio);
}
}
CGFloat scaleRatio = bounds.size.width/width;
CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
CGFloat boundHeight;
UIImageOrientation orient = image.imageOrientation;
switch(orient) {
case UIImageOrientationUp: //EXIF = 1
transform = CGAffineTransformIdentity;
break;
case UIImageOrientationUpMirrored: //EXIF = 2
transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
break;
case UIImageOrientationDown: //EXIF = 3
transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationDownMirrored: //EXIF = 4
transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
break;
case UIImageOrientationLeftMirrored: //EXIF = 5
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0);
break;
case UIImageOrientationLeft: //EXIF = 6
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0);
break;
case UIImageOrientationRightMirrored: //EXIF = 7
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI/2.0);
break;
case UIImageOrientationRight: //EXIF = 8
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI/2.0);
break;
default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
}
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
CGContextScaleCTM(context, -scaleRatio, scaleRatio);
CGContextTranslateCTM(context, -height, 0);
}
else {
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
}
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
+0
我也創建了一個例子,其中攝像頭在橫向模式下打開,並且僅在橫向模式下拍攝圖片 – nivritgupta
相關問題
- 1. 強制相機在橫向模式下拍攝圖像
- 2. 強制UIImagePickerController以橫向模式拍攝視頻
- 3. 如何檢查在android中使用攝像頭在縱向模式還是橫向模式下拍攝圖像?
- 4. android:configChanges =「screenSize」參數在橫向模式下拍攝肖像高度
- 5. 在縱向模式下在移動Safari上拍攝的Filepicker.io圖像橫向
- 6. 如何在橫向模式下拍攝照片[iOS8]?
- 7. 橫向模式下的UIImagepickercontroller
- 8. 如何強制UIImagePickerController以橫向模式錄製視頻
- 9. 使用UIImagePickerController拍攝圖像
- 10. UIImagePickerController在iphone中使用橫向模式的攝像頭選項
- 11. 強制攝像機視圖在方向鎖定的橫向上
- 12. 在肖像模式下拍攝的圖片應該保留在橫向模式下android
- 13. 如何強制攝像頭在橫向發送視頻?
- 14. UIImagePickerController僅支持肖像模式。任何支持橫向模式的替代品?
- 15. 在橫向模式下鎖定特定的UIViewController +強制橫向模式
- 16. 如何強制TextField在橫向模式下完全拉伸
- 17. 如何強制在橫向模式下顯示鍵盤?
- 18. 強制視圖僅支持橫向模式
- 19. Android:在風景模式下拍攝的照片強制
- 20. 如何僅在橫向模式下限制j2me應用程序
- 21. UIImgePickerView在橫向拍攝的圖像在顯示時拉伸
- 22. 設備處於橫向拍攝時拍攝人像的任何問題?
- 23. Android SCREEN_ORIENTATION_PORTRAIT僅在橫向模式下顯示縱向視圖
- 24. iPhone,如何強制一個視圖進入橫向模式?
- 25. 我可以強制iPad僅在橫向模式下顯示網站嗎?
- 26. Xcode僅在橫向拍攝照片/視頻
- 27. 如何在橫向模式下打印圖像
- 28. UIImagePickerController攝像頭預覽是橫向應用中的縱向
- 29. 如何更改橫向模式下圖像視圖的位置
- 30. 如何在橫向模式下打開視圖控制器?
http://stackoverflow.com/questions/14484816/force-uiimagepickercontroller-to-take-photo-in-portrait-orientation-dimensions-i ...那麼我認爲你會發現風景呢? – IronManGill
可能的重複http://stackoverflow.com/questions/5737632/open-uiimagepickercontroller-in-landscape-mode – Maulik
可能重複的[在UIImagePickerController強制橫向方向](http://stackoverflow.com/questions/14618546/force -landscape-orientation-in-uiimagepickercontroller) – Hemang