zoukankan      html  css  js  c++  java
  • ios本地相册 照像 本地视频

     1 -(IBAction)btnClick{
     2    UIActionSheet* actionSheet = [[UIActionSheet alloc]
     3                                  initWithTitle:nil
     4                                  delegate:self
     5                                  cancelButtonTitle:@"取消"
     6                                  destructiveButtonTitle:nil
     7                                  otherButtonTitles:@"照相机",@"摄像机",@"本地相册",@"本地视频",nil];
     8             [actionSheet showInView:self.view];
     9             [actionSheet release];
    10 }
     1 #pragma UIActionSheet Delegate
     2 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
     3 {   
     4     NSLog(@"buttonIndex = [%d]",buttonIndex);
     5     switch (buttonIndex) {
     6         case 0://照相机
     7             {                 
     8                 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
     9                 imagePicker.delegate = self;
    10                 imagePicker.allowsEditing = YES;
    11                 imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    12                 imagePicker.mediaTypes =  [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
    13                 [self presentModalViewController:imagePicker animated:YES];
    14                 [imagePicker release];
    15             }
    16             break;
    17         case 1://摄像机
    18             {                 
    19                 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    20                 imagePicker.delegate = self;
    21                 imagePicker.allowsEditing = YES;
    22                 imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    23                 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
    24                 imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow;
    25                 [self presentModalViewController:imagePicker animated:YES];
    26                 [imagePicker release];
    27             }
    28             break;
    29         case 2://本地相册
    30             {                 
    31                 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    32                 imagePicker.delegate = self;
    33                 imagePicker.allowsEditing = YES;
    34                 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    35                 imagePicker.mediaTypes =  [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
    36                 [self presentModalViewController:imagePicker animated:YES];
    37                 [imagePicker release];
    38             }
    39             break;
    40         case 3://本地视频
    41             {                 
    42                 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    43                 imagePicker.delegate = self;
    44                 imagePicker.allowsEditing = YES;
    45                 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    46                 imagePicker.mediaTypes =  [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
    47                 [self presentModalViewController:imagePicker animated:YES];
    48                 [imagePicker release];
    49             }
    50             break;
    51         default:
    52             break;
    53     }
    54 }
     1 //选取的文件便保存在了filedata中。就可以随时过来调用了
     2 #pragma UIImagePickerController Delegate
     3 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
     4 {
     5     if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) {
     6         UIImage  *img = [info objectForKey:UIImagePickerControllerEditedImage];
     7         self.fileData = UIImageJPEGRepresentation(img, 1.0);
     8     } else if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) {
     9         NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
    10         self.fileData = [NSData dataWithContentsOfFile:videoPath]; 
    11     }
    12     [picker dismissModalViewControllerAnimated:YES];
    13 }
    14 
    15 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
    16 {
    17     [picker dismissModalViewControllerAnimated:YES];
    18 }
  • 相关阅读:
    火炬之光模型导出(Unity载入火炬之光的模型)
    树的左旋与右旋
    javaEE开发之导出excel工具类
    STL algorithm算法is_permutation(27)
    学做衣服论坛 -服装DIY教程,缤纷服装网,裁剪教程,家用缝纫机,买布料
    傲娇_百度百科
    《失败不是成功之母》阅读理解
    失败是不是成功之母
    正则表达式多语种的web版本
    date tod = boost::gregorian::day_clock::local_day(); //当前日期
  • 原文地址:https://www.cnblogs.com/wangshengl9263/p/3230776.html
Copyright © 2011-2022 走看看