iPhone應用開發之調用系統照相機
作者:佚名
本文介紹的是IPhone應用開發之UIImagePickerController調用系統照相機,很詳細的介紹了iphone應用程序的一個實例,來看內容。
IPhone應用開發之UIImagePickerController調用系統照相機是本文要介紹的內容,不多說,我們來看內容。iphone api中提供了調用系統照相機的接口,我們只需調用相應的界面,即刻在自己的程序中獲取相機圖片.下面是一個非常簡單的調用系統照相機的例子.
相應的界面如下:
***可以編輯圖片和使用相應的圖片.
下面是主要代碼:
- - (void) addPicEvent
- {
- //先設定sourceType為相機,然后判斷相機是否可用(ipod)沒相機,不可用將sourceType設定為相片庫
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
- if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
- sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- }
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.allowsEditing = YES;
- picker.sourceType = sourceType;
- [self presentModalViewController:picker animated:YES];
- [picker release];
- }
- - (void)saveImage:(UIImage *)image {
- NSLog(@"保存");
- }
- #pragma mark –
- #pragma mark Camera View Delegate Methods
- - (void)imagePickerController:(UIImagePickerController *)picker
- didFinishPickingMediaWithInfo:(NSDictionary *)info {
- [picker dismissModalViewControllerAnimated:YES];
- UIImage *image = [[info objectForKey:UIImagePickerControllerEditedImage] retain];
- [self performSelector:@selector(saveImage:)
- withObject:image
- afterDelay:0.5];
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
- [picker dismissModalViewControllerAnimated:YES];
- }
源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/CameIphone/
小結:IPhone應用開發之UIImagePickerController調用系統照相機的內容介紹完了,希望本文對你有所幫助!
責任編輯:zhaolei
來源:
互聯網