相机问题

时间:2010-08-12 08:40:14

标签: iphone objective-c image camera

我目前正在开发一个应用程序,该应用程序正在使用UIImagePickerController在相机中构建照片。

我不想做的是为用户提供UIImagePickerController底栏上的开关,以便能够在前后摄像头之间切换(如果可用的话)。我知道如何确定是否有前置摄像头,但如何在底部栏上显示这样的开关呢?

Thanx为您提供所有帮助!

2 个答案:

答案 0 :(得分:1)

.h文件 @property(nonatomic)UIImagePickerControllerCameraDevice cameraDevice;

cameraButtonPressed方法打开后置摄像头。 changeCam方法在后置和前置摄像头之间切换。

.m文件


-(void) cameraButtonPressed

{
 overLay=[[UIView alloc]initWithFrame:CGRectMake(0,0, 320, 480)];

 UIImage *CameraClickImg=[UIImage imageNamed:@"capture.png"];
 UIButton *captureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
 [captureBtn setFrame:CGRectMake(35,440, 240,40)];
 [captureBtn addTarget:self action:@selector(captureImage) forControlEvents:UIControlEventTouchUpInside];
 [captureBtn setImage:CameraClickImg forState:UIControlStateNormal];



 UIButton *changeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
 [changeBtn setFrame:CGRectMake(250,30, 40,40)];
 [changeBtn addTarget:self action:@selector(changeCam) forControlEvents:UIControlEventTouchUpInside];
 [changeBtn setImage:CameraClickImg forState:UIControlStateNormal];


 picker = [[UIImagePickerController alloc] init];
 picker.delegate = self;
 picker.allowsEditing = NO;
 picker.sourceType = UIImagePickerControllerSourceTypeCamera;
 picker.showsCameraControls=NO;
 picker.cameraFlashMode =  UIImagePickerControllerCameraFlashModeOff;
 picker.cameraOverlayView=overLay;
 [self presentModalViewController: picker animated:YES];
 [overLay addSubview:captureBtn];
 [overLay addSubview:changeBtn];

 [picker release];

 [self.view addSubview:activityIndicator];

}


-(void)captureImage
{

 [picker takePicture];


}


-(void)changeCam
{
 if (picker.cameraDevice==UIImagePickerControllerCameraDeviceRear) 
  picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
 else
  picker.cameraDevice=UIImagePickerControllerCameraDeviceRear;


}

答案 1 :(得分:0)

showsCameraControls的{​​{1}}设置为UIImagePickerController,或者使用YES提供您自己的控件。

要在前后摄像头之间切换,请使用cameraOverlayView的{​​{1}}属性。