IOS 开发调用摄像头

参照文章:http://www.cnblogs.com/gcb999/p/3223469.html

                      http://blog.sina.com.cn/s/blog_9693f61a01016alr.html

@interface ViewController ()
@end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame=CGRectMake(0, 0, 200, 50); [button setTitle:@"aa" forState:UIControlStateNormal]; [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } //调动摄像头拍摄 -(void)click:(UIButton *)btn{ UIImagePickerController *imagePicker=[[UIImagePickerController alloc] init]; imagePicker.delegate=self; // imagePicker.view.frame=s if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; } // imagePicker.allowsEditing=YES; // [self.view addSubview:imagePicker.view]; [self presentViewController:imagePicker animated:YES completion:^{ }]; 

#pragma mark------从相册选择------------

- (void) chooseFromAlbum {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;

    picker.allowsEditing = NO;

    //从相册列表选取

    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        //此处设置只能使用相机,禁止使用视频功能

//        picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];

    }

    [self presentViewController:picker animated:YES completion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"%@",info);
  UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];

    self.image.image=image;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


#pragma mark---保存相册到本地-------

 
 

 

 
 

- (void)saveImage

 
 

{

 
 

    int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;

    ZoomScroll *currentImageView = _scrollView.subviews[index];

    UIImageWriteToSavedPhotosAlbum(currentImageView.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] init];

 
 

    indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

 
 

    indicator.center = self.center;

 
 

    _indicatorView = indicator;

 
 

    [[UIApplication sharedApplication].keyWindow addSubview:indicator];

 
 

    [indicator startAnimating];

 
 

}

 
 

 

 
 

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;

 
 

{

 
 

    [_indicatorView removeFromSuperview];

    UILabel *label = [[UILabel alloc] init];

 
 

    label.textColor = [UIColor whiteColor];

 
 

    label.backgroundColor = [UIColor colorWithRed:0.1f green:0.1f blue:0.1f alpha:0.90f];

 
 

    label.layer.cornerRadius = 5;

 
 

    label.clipsToBounds = YES;

 
 

    label.bounds = CGRectMake(0, 0, 150, 30);

 
 

//    label.frame = SIZE_RectMake((ScreenWidth - label.bounds.size.width)/2, -10, 150, 30);

 
 

    label.center = self.center;

 
 

    

 
 

    label.textAlignment = NSTextAlignmentCenter;

 
 

    label.font = [UIFont boldSystemFontOfSize:17];

 
 

    [[UIApplication sharedApplication].keyWindow addSubview:label];

 
 

    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:label];

 
 

    if (error) {

 
 

        label.text = SDPhotoBrowserSaveImageFailText;

 
 

    }   else {

 
 

        label.text = SDPhotoBrowserSaveImageSuccessText;

 
 

    }

 
 

    

 
 

//    [UIView animateWithDuration:0.4 animations:^{

 
 

//        label.frame = SIZE_RectMake((ScreenWidth - label.bounds.size.width)/2, (ScreenHeight - 30)/2, 150, 30);

 
 

//    }];

 
 

//    // 延迟2秒执行

 
 

//    

 
 

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 
 

//        [UIView animateWithDuration:0.25  animations:^{

 
 

//            

 
 

//            label.frame = SIZE_RectMake((ScreenWidth - label.bounds.size.width)/2, (ScreenHeight - 30)/2 - 30, 150, 30);

 
 

//            NSLog(@"11111");

 
 

//            

 
 

//        }];

 
 

//    });

 
 

//

 
 

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW + 0.4, (int64_t)(2.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 
 

//        [UIView animateWithDuration:0.4 animations:^{

 
 

//            NSLog(@"2222");

 
 

//            label.frame = SIZE_RectMake((ScreenWidth - label.bounds.size.width)/2 , (ScreenHeight + 5), 150, 30);

 
 

//            

 
 

//        }];

 
 

//    });

 
 

//    

 
 

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW + 5, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 
 

//        

 
 

//         NSLog(@"33333");

 
 

//        [label removeFromSuperview];

 
 

//       

 
 

//    });

 
 

    

 
 

    [label performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0];

 
 

}

 

转载于:https://www.cnblogs.com/mr-huang-wei-bo/p/4428395.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值