• 拍摄相片


    <UIImagePickerControllerDelegate>


    - (IBAction)takePicture:(id)sender { // Make sure camera is available //UIImagePickerControllerSourceTypePhotoLibrary,访问设备上保存的所有照片 //UIImagePickerControllerSourceTypeCamera, //UIImagePickerControllerSourceTypeSavedPhotosAlbum只能用于访问Camera Roll相册 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Camera Unavailable" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; [alert show]; return; } if (self.imagePicker == nil) { self.imagePicker = [[UIImagePickerController alloc] init]; self.imagePicker.delegate = self; self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; self.imagePicker.allowsEditing = YES;//可编辑状态 } [self presentViewController:self.imagePicker animated:YES completion:NULL]; }
    //取回相片、更新图像视图,隐藏图像选取器
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];//可编辑状态
        UIImageWriteToSavedPhotosAlbum (image, nil, nil , nil);//照片保存到相册中
        self.imageView.image = image;
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;//充满整个视图

    //self.imageView.contentMode = UIViewContentModeScaleAspectFit;//固定纵横比显示整张图片

    [self dismissViewControllerAnimated:YES completion:NULL];
    }
    //取消图片选择,隐藏图片选择器
    - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
    {
        [self dismissViewControllerAnimated:YES completion:NULL];
    }

     

  • 相关阅读:
    2017暑期集训Day 4
    2017暑期集训Day 5
    2017暑期集训Day 3
    Codeforces Round #433
    校内集训(20170906)
    校内集训(20170903)
    培训补坑(day10:双指针扫描+矩阵快速幂)
    培训补坑(day8:树上倍增+树链剖分)
    培训补坑(day7:线段树的区间修改与运用)(day6是测试,测试题解以后补坑QAQ)
    培训补坑(day5:最小生成树+负环判断+差分约束)
  • 原文地址:https://www.cnblogs.com/fengmin/p/5520642.html
Copyright © 2020-2023  润新知