美文网首页
iOS 相册

iOS 相册

作者: Satanshun | 来源:发表于2016-10-12 11:26 被阅读0次

    相机权限:Privacy - Camera Usage Description string: 是否允许此App使用你的相机?

    相册权限:Privacy - Photo Library Usage Description string: 是否允许此App访问你的媒体资料库?

    在info.plist加上这一条这样就可以使相册显示出中文

    Localized resources can be mixed 设置为 YES。

    //相册

    - (void)photo{

    //导入协议 <UIImagePickerControllerDelegate,UINavigationControllerDelegate>

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

     [self presentViewController:imagePicker animated:YES completion:^{        imagePicker.delegate = self;        

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

       }];

    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info

    {

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    self.imageView.image = image;

    //返回图像修圆

    //[self.imageView.layer setCornerRadius:CGRectGetHeight([self.hearView bounds])/2];

    //self.imageView.layer.masksToBounds = YES;

    [picker dismissViewControllerAnimated:YES completion:^{

    //可使用通知传图片到上一页赋值

    }];

    }

    //摄像头

    - (void)camera

    {

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

    [self presentViewController:imagePick animated:YES completion:^{

    BOOL iscamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];

    if (!iscamera) {

    NSLog(@"没有摄像头");

    return;

    }

    imagePick.delegate = self;

    imagePick.sourceType = UIImagePickerControllerSourceTypeCamera;

    //imagePick.allowsEditing = YES;

    }];

    }

    //比较两张图片是否相似

    NSData *data = UIImagePNGRepresentation(_hearView.image);

    UIImage *image = [UIImage imageNamed:@"Photoicons@2x"];

    NSData *data1 = UIImagePNGRepresentation(image);

    if ([data isEqual:data1]) {

    NSLog(@"-----------相似");

    }

    相关文章

      网友评论

          本文标题:iOS 相册

          本文链接:https://www.haomeiwen.com/subject/ywkiyttx.html