zoukankan      html  css  js  c++  java
  • 调用本地相册、相机

    1、       判断系统是否支持相机

    [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]

    2、       创建相册视图控制器对象

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

    3、       设置sourceType(资源类型)

    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;//相机

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//图片库

    imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//保存的图片

    4、       设置弹出动画(可选)

    imagePickerController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

    5、       设置是否允许编辑图片

    imagePickerController.allowsEditing = YES;

    6、       设置代理(UIImagePickerControllerDelegate)

    imagePickerController.delegate = self;

    7、       实现代理方法:获取图片

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

    {

         [picker dismissViewControllerAnimated:YES completion:nil];

        //获取图片

         UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    }

    //取消点击

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

    {

        [self dismissViewControllerAnimated:YES completion:^{}];

    }

    8、       保存图片到相册

    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);// image:要保存的图片UImage对象,

    - (void) image: (UIImage *) image

    didFinishSavingWithError: (NSError *) error

       contextInfo: (void *) contextInfo{

    //如果error==NULL,则表示图片保存成功

    }

  • 相关阅读:
    css如何使背景图片水平居中
    HTML特殊符号显示技巧
    自定义jquery插件
    bootstrap学习以及其插件
    自定义checkbox样式
    maven java.lang.OutOfMemoryError:PermGEn space
    Java多线程学习(吐血超详细总结)
    Maven .m2 setting.xml配置
    html a标签打开邮件
    File 类
  • 原文地址:https://www.cnblogs.com/liuguan/p/5198414.html
Copyright © 2011-2022 走看看