iphone和ipad拍照功能的实现

iphone和ipad拍照功能的实现,第1张

概述在iphone和ipad中,拍照的实现是不同的。 在iphone中: if([UIImagePickerController   isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { picker = [[UIImagePickerController alloc] init]; picker.delegate = se

在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拍照功能的实现所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1089885.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存