1天学习1个类 UIImagePickerController 示例
来源:互联网 发布:中信淘宝信用卡好吗 编辑:程序博客网 时间:2024/06/02 05:50
真机就不截图了.
直接发代码,大家可以拷贝代码直接测试~
//// main.m// ControlDemo//// Created by watsy0007 on 12-6-3.// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.//#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate> {}@end@implementation ViewController- (void) dealloc { [super dealloc];}- (void) RecordMovie:(id) sender { @autoreleasepool { UIImagePickerController *imagePickerController = (UIImagePickerController *) sender; sleep(2); if (imagePickerController.cameraCaptureMode == UIImagePickerControllerCameraCaptureModePhoto) { [imagePickerController takePicture]; } else { [imagePickerController startVideoCapture]; sleep(10); [imagePickerController stopVideoCapture]; } } }- (void) BarItemAction:(id) sender { if ([UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; //允许编辑 imagePickerController.allowsEditing = YES; // //相机模式// imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; //前后 imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; //闪光灯模式 imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; //叠加view UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)]; view.center = self.view.center; view.backgroundColor = [UIColor lightTextColor]; imagePickerController.cameraOverlayView = view; [view release]; //旋转视图 imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(0.5, 0.5); //允许模式 imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera]; //最长时间支持 imagePickerController.videoMaximumDuration = 100; //视频质量 imagePickerController.videoQuality = UIImagePickerControllerQualityTypeLow; NSLog(@"\n[UIImagePickerController availableCaptureModesForCameraDevice]\n{\n\t%@\n}",[UIImagePickerController availableCaptureModesForCameraDevice:UIImagePickerControllerCameraDeviceFront]); NSLog(@"\n[UIImagePickerController isCameraDeviceAvailable]\n{\n\t%d\n}",[UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]); NSLog(@"\n[UIImagePickerController isFlashAvailableForCameraDevice]\n{\n\t%d\n}",[UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]); NSLog(@"\n[UIImagePickerController isSourceTypeAvailable]\n{\n\t%d\n}",[UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]); // imagePickerController.showsCameraControls = NO; [self presentModalViewController:imagePickerController animated:YES]; [NSThread detachNewThreadSelector:@selector(RecordMovie:) toTarget:self withObject:imagePickerController]; [imagePickerController release]; } else { for (id label in self.view.subviews) { if ([label isKindOfClass:[UILabel class]]) { [(UILabel*)label setText:@"不支持模拟器"]; } } } }- (UIBarButtonItem *) createNewItem { UIBarButtonItem *item; item = [[UIBarButtonItem alloc] initWithTitle:@"相机" style:UIBarButtonItemStylePlain target:self action:@selector(BarItemAction:)]; return [item autorelease];}- (void) loadView { [super loadView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; label.frame = CGRectMake(0, 0, 320, 420); label.numberOfLines = 3; label.textAlignment = UITextAlignmentCenter; label.text = @"watsy0007 \n QQ:258841679\n群:125807534"; [self.view addSubview:label]; [label release]; self.title = @"UIDatePicker Class Reference Demo"; self.navigationItem.rightBarButtonItem = [self createNewItem];}- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES;}- (void) viewDidLoad { [super viewDidLoad];}#pragma mark -#pragma mark UIImagePickerDelegate delegate- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { NSLog(@"\ndidFinishPickingImage : \n{\t%@\n}",editingInfo);}- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"\ndidFinishPickingMediaWithInfo : \n{\t%@\n}",info);}- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker { NSLog(@"imagePickerControllerDidCancel");}@end@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) UIViewController *viewController;@end@implementation AppDelegate@synthesize window = _window;@synthesize viewController = _viewController;- (void) dealloc { [_window release]; [_viewController release]; [super dealloc];}- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.viewController = [[ViewController alloc] init]; UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = controller; [controller release]; [self.window makeKeyAndVisible]; return YES;}@endint main(int argc, char *argv[]){ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}
- 1天学习1个类 UIImagePickerController 示例
- 1天学习1个类 UIBarButtomItem 类 示例
- 1天学习1个类 UIButton 类 示例
- 1天学习1个类 UIDatePicker 类 示例
- UIImagePickerController学习
- UIImagePickerController学习
- IOS 摄像头使用(1)-UIImagePickerController
- IOS 摄像头使用(1)-UIImagePickerController
- IOS 摄像头使用(1)-UIImagePickerController
- IOS 摄像头使用(1)-UIImagePickerController
- springboot学习笔记-1 第一个springboot示例
- Mongodb MapReduce示例1个
- SQLLoader学习示例1
- Makefile学习之一个示例
- 1天学习1个类库 UILocalNotification 示例
- UIImagePickerController
- UIImagePickerController
- UIImagePickerController
- 破解入门(二)-----认识OllyDBG
- 【Android应用开发】-(6)响应灵敏性设计(Designing for Responsiveness)
- 项目管理也要懂架构
- eas 框架
- 每天工作4小时的程序员
- 1天学习1个类 UIImagePickerController 示例
- 集合框架
- SQL Server 2012 开发新特性:文件表
- Drupal 7如何实现在后台以表格,列表的形式管理网站的内容?像数据库表一样?
- 基于stun,turn ,ice协议的 SBC服务器
- Matlab优化函数linprog的使用
- Ural1517 Freedom of choice, 后缀数组,最长公共子串
- 利用Apache的commons-net实现FTP的文件读取、上传、下载、删除和移动功能
- SQL Server 2012 安全新特性:包含数据库