HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone和ipad拍照功能的实现大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在iphone和ipad中,拍照的实现是不同的。

在iphone中:

if([UIImagePickerController   issourceTypeAvailable:UIImagePickerControllersourceTypeCamera])

{

picker = [[UIImagePickerController alloc] init];

picker.delegate = self;

picker.sourCEType = UIImagePickerControllersourceTypeCamera;

picker.allowsEdiTing = NO;

picker.showsCameraControllers = YES;

  [self presentModalViewController:m_imagePicker animated:YES];
  [m_imagePicker release];
}else {
  UIAlertView *alert = [[UIAlertView alloc]initWithtitle:nil message:@”" delegate:nil cancelButtontitle:@”Close” otherButtontitles:nil];
  [alert show];
  [alert release];
}

即可调用相机拍照,但在ipad中,需要通过UIPopoverController来实现,或者通过openGL也可实现,如下

if([UIImagePickerController issourceTypeAvailable:UIImagePickerControllersourceTypeCamera])

{

picker = [[UIImagePickerController alloc] init];

picker.delegate = self;

picker.sourCEType = UIImagePickerControllersourceTypeCamera;

picker.allowsEdiTing = NO;

picker.modalPresentationStyle = UIModalPresentationCurrentContext;

UIViewController * myViewController = [[UIViewController alloc] init];

[[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];

[myViewController presentModalViewController:picker animated:YES];

[myViewController setModalPresentationStyle:UIModalPresentationCurrentContext];

}

对于拍照的控制需要使用UIImagePickerControllerDelegate的三个方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image ediTingInfo:(NSDictionary *)ediTingInfo

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

一般来说,如果item中包含image和video时,需要使用didFinishPickingMediaWithInfo的方法,拍照后在未保存图片之前,照片的信息会存放在缓存中,这时通过保存图片信息的字典中内容可以获取所拍照片,实现如下

- (void) imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage * photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

所得的照片有一个只读的属性imageOrientation,它记录照片拍摄时的方向,在某些情况下,这个属性是非常有用的。还有一点容易忽略的东西,使用ipad拍的照片大小是960*720,而不是1024*768。

大佬总结

以上是大佬教程为你收集整理的iphone和ipad拍照功能的实现全部内容,希望文章能够帮你解决iphone和ipad拍照功能的实现所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。