react native 相机拍照

安装插件

npm install react-native-image-picker
// 引入
import { launchCamera, launchImageLibrary} from 'react-native-image-picker';

 代码如下

<Button title="点击启动相机" onPress={() => takePhoto()}></Button>
<Button title="点击启动相册" onPress={() => addPhoto()}></Button>


// 相册选择图片
const addPhoto = () => {
  launchImageLibrary(
    {
      mediaType: 'photo', //'photo'照片, 'video'视频, 'mixed'混合
      selectionLimit: 1, // 1为一张,0不限制数量
    },
    res => {
      if (res.assets) {
        console.log(res.assets)
      }
    },
  );
};
// 相机拍照
const takePhoto = () => {
  launchCamera(
    {
      mediaType: 'photo', // 'photo'照片, 'video'视频, 'mixed'混合
      cameraType: 'back', //'back'后置摄像头, 'front'前置相机
    },
    res => {
      if (res.assets) {
        console.log(res.assets)
      }
    },
  );
};

相关推荐

  1. react native 相机拍照

    2024-04-08 23:40:01       37 阅读
  2. Android Compose 调用系统相机拍照

    2024-04-08 23:40:01       56 阅读
  3. 小程序调用相机拍照上传

    2024-04-08 23:40:01       37 阅读
  4. Android10以上版本调用相机拍照

    2024-04-08 23:40:01       35 阅读
  5. android 13 相册拍照问题

    2024-04-08 23:40:01       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 23:40:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 23:40:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 23:40:01       82 阅读
  4. Python语言-面向对象

    2024-04-08 23:40:01       91 阅读

热门阅读

  1. 贪婪算法python实现

    2024-04-08 23:40:01       41 阅读
  2. nuxt3使用记录二:页面构建的细节(特别是SSG)

    2024-04-08 23:40:01       41 阅读
  3. es6新增加的语法

    2024-04-08 23:40:01       31 阅读
  4. 自建ceph存储集群方案之从零到一

    2024-04-08 23:40:01       38 阅读
  5. 机器视觉系统-为什么需要机器视觉光源

    2024-04-08 23:40:01       38 阅读
  6. [算法刷题打卡]Day9

    2024-04-08 23:40:01       34 阅读
  7. 字符串约束

    2024-04-08 23:40:01       38 阅读