# react-Native-yuanxincamera **Repository Path**: higgs/react-Native-yuanxincamera ## Basic Information - **Project Name**: react-Native-yuanxincamera - **Description**: No description available - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2016-12-13 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 使用介绍 ### npm 安装 1.在项目根目录的package.js里添加 "react-native-yuanxincamera": "git+http://yxsource.sinooceanland.net/platform/react-Native-yuanxincamera.git" 2.执行 npm install ### IOS 配置 1.在项目中选中Libraries文件夹,右键选择add File to "你的工程",在node_modules文件夹下找到react-native-yuanxincamera/ios/YuanXinCamera.xcodeproj,add到项目中 2.选中项目在targets中的General选项中找到Linked Frameworks and Libraries并添加YuanXinCamera.a 3.选中YuanXinCamera.xcodeproj项目在targets中的Build Settings选卡中找到Header Search Paths中添加$(SRCROOT)/../node_modules/react-native-yuanxincamera/ios 4.找到项目中左侧YuanXinCamera.xcodeproj->YuanXinCamera->Camere->CamereManager->YuanXinCamera.bundle,拖拽到名称下 不用选Copy items if needed **注意事项:**Xcode8以后需要 在项目在targets中的Info选项中的Custom iOS Target Properties中添加如下 否则会崩溃 Privacy - Camera Usage Description ->是否允许此App使用你的相机 Privacy - Microphone Usage Description->是否允许此App使用你的麦克风 Privacy - Photo Library Usage Description->是否允许此App访问你的媒体资料 ### android #### 1.在setting.gradle配置 include ':react-native-yuanxincamera' project(':react-native-yuanxincamera').projectDir = new File(settingsDir, '../node_modules/react-native-yuanxincamera/android') #### 2.在build.gradle中复制 compile project(':react-native-yuanxincamera') #### 3.在ManiAppalachian添加引用 new ChoosePackage() #### 4.在MainActivity中添加如下代码 ``` private static final int REQUEST_IMAGE = 2; private static final int PERMISSION_CODE = 555; private static final int CAMERA_VIDEO = 200; private static final int CAMERA_PIC = 100; public ArrayList mSelectPath; public List CreateSfPath; private WritableArray writableArray; private WritableArray writableArrayslt; private WritableArray writableArrayispv; int IsPicVideo = 0; 在onActivityResult()方法中添加 { if (requestCode == REQUEST_IMAGE) { if (resultCode == RESULT_OK) { SharedPreferences sp = getSharedPreferences(CustomConstant.sharedName, Activity.MODE_PRIVATE); String type = sp.getString("type", "json"); String ShowChoosePath = sp.getString("ShowChoosePath", "showImagePicker"); Log.e("TAG", "ShowChoosePath-" + ShowChoosePath+"-type-" + type); mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); Log.e("TAG", "Main--mSelectPath--" + mSelectPath); CreateSfPath = new ArrayList(); WritableArray writableArray2 = Arguments.createArray(); WritableMap writableMap1 = null; for (int i = 0; i < mSelectPath.size(); i++) { writableMap1 = Arguments.createMap(); String path = mSelectPath.get(i); Log.e("TAG", "正常路径---" + path); if(path.endsWith("mp4")){ writableMap1.putInt("type",1); writableMap1.putString("filePath",path); writableArray2.pushMap(writableMap1); } else { writableMap1.putInt("type",0); writableMap1.putString("filePath",path); writableArray2.pushMap(writableMap1); } } WritableMap writableMap = Arguments.createMap(); if (LocalUtil.getStorageData(this, CustomConstant.tag) != null) { writableMap.putString("tag", LocalUtil.getStorageData(this, CustomConstant.tag)); LocalUtil.clearStorageData(this, CustomConstant.tag); } if (type == "" || type.equals("json")) { if (ShowChoosePath.equals("showImagePicker")) { writableMap.putString("data", new Gson().toJson(mSelectPath)); MainApplication.getInstance().getChoosePackage().imageResultCallback.meature(writableMap); } else if (ShowChoosePath.equals("launchImageLibrary")) { MainApplication.getInstance().getChoosePackage().imageResultCallback.LaunchMeature(writableArray2); } } else { writableArray = Arguments.createArray(); for (String item : mSelectPath) { writableArray.pushString(item); } writableArrayslt = Arguments.createArray(); for (String item : CreateSfPath) { writableArrayslt.pushString(item); } writableArrayispv = Arguments.createArray(); writableArrayispv.pushInt(IsPicVideo); if (ShowChoosePath.equals("showImagePicker")) { writableMap.putArray("data", writableArray); MainApplication.getInstance().getChoosePackage().imageResultCallback.meature(writableMap); } else if (ShowChoosePath.equals("launchImageLibrary")) { Log.e("TAG","没有Array返回..."); } } } } else if (requestCode == PERMISSION_CODE) { Log.e("TAG", "PERMISSION_CODE"); SharedPreferences sp = getSharedPreferences(CustomConstant.sharedName, Activity.MODE_PRIVATE); int total = sp.getInt("total", 0); boolean isCut = sp.getBoolean("isCut", false); String tag = sp.getString("tag", null); boolean isShowCamera = sp.getBoolean("isShowCamera", false); int isPicVideo = sp.getInt("isPicVideo", 0); Log.e("TAG", "total-" + total + "-isCut-" + isCut + "-tag-" + tag); MainApplication.getInstance().getChoosePackage().localImageChooseModule.ChooseImage(total, isCut, tag, this, isShowCamera, isPicVideo); } else if (requestCode == CAMERA_VIDEO) { Uri uri = data.getData(); String UriPath = ChooseFileUtils.getUriPath(this, uri); Log.e("TAG", "录制视频成功-UriPath---" + UriPath + "---uri---" + uri); WritableMap writableMap = Arguments.createMap(); writableMap.putString("FilePathVideo", UriPath); writableMap.putInt("type", 1); MainApplication.getInstance().getChoosePackage().imageResultCallback.CameraVideo(writableMap); } else if (requestCode == CAMERA_PIC) { SharedPreferences sp = getSharedPreferences(CustomConstant.sharedName, Activity.MODE_PRIVATE); String PicFilePath = sp.getString("PicFilePath", null); Log.e("TAG", "拍照成功-PicFilePath---" + PicFilePath); WritableMap writableMap = Arguments.createMap(); writableMap.putString("FilePathPic", PicFilePath); writableMap.putInt("type", 0); MainApplication.getInstance().getChoosePackage().imageResultCallback.CameraPic(writableMap); } } ``` #### 5.在AndroidManifest.xml添加 ``` 权限 ``` #### 6.在styles中添加 ``` ``` #### 7. 在MainApplication添加 ``` private static MainApplication instance; private static ChoosePackage choosePackage; public static ChoosePackage getChoosePackage() { return choosePackage; } public static MainApplication getInstance() { return instance; } onCreate() 方法 instance = this; getPackage() 方法 choosePackage = new ChoosePackage(); choosePackage ``` ####8. build ``` compile 'com.google.code.gson:gson:2.2.4' ``` ### 使用方式 引入包文件 import { ImageManager } from 'react-native-yuanxincamera'; 选照片 ``` ImageManager.showImagePicker({ maxCount: 9, //最多能选几张 默认是9 photoAlbumName:'',//照相保存相册名字 不给是项目名称 videoAlumName:'',//小视频保存相册名字 不给是项目名称 isShowCamera: true ,//false->不显示内部照相 true->显示内部照相 默认是显示 columnNumber:4,//选择照片时显示几数列 默认是4 }).then(result => { console.log(result); }).catch(er => { console.log(er); }); ``` 返回结果 type 0->z照片 1->视频 ( {filePath = “”;type = 0;},….. ) 选视频 或选照片 ``` ImageManager.launchImageLibrary({ IsChoose: 0, // 0 图片 1视频 默认是选照片 videoAlumName:'',//小视频保存相册名字 不给是项目名称 photoAlbumName:'',//照相保存相册名字 不给是项目名称 isShowCamera: true ,//false ->不显示内部照相 true->显示内部照相 columnNumber:4,//选择照片时显示几数列 默认是4 maxCount: 3,//最多选择个数 默认是3个 maxSecond:6,//内部录制小视频最长秒数 默认是6秒 }).then(result => { console.log(result); }).catch(er => { console.log(er); }); ``` 返回结果 type 0->照片 1->视频 ( {filePath = “”;type = 0;},….. ) 拍照 和录视频 ``` ImageManager.launchCamera({ IsCamera: 0 ,// 0 拍照 1录制视频 videoAlumName:'',//小视频保存相册名字 不给是项目名称 photoAlbumName:'',//照相保存相册名字 不给是项目名称 maxSecond:6,//录制小视频最长秒数 }).then(result => { console.log(result); }).catch(er => { console.log(er); }); ``` 返回结果 type 0->z照片 1->视频 {filePath = “”;type = 0;} 根据照像路径,获取图片的Base 64 import { ReadImageManager } from 'react-native-yuanxincamera'; 获取单张图片Base 64 ``` ReadImageManager.readImage({ filePath:'',// 手机本地存储路径 (如react-native-yuanxincamera) 必填 scale:1,//图片压缩比例,不改变大小的怀况下,最大值为1,最小值是0 width: 0,//默认是0 不做大小缩放处理 与height 相关 height:0,//默认是0 不做大小缩放处理 与width 相关 objectKey:'', //唯一id 。 }).then(result => { {"filePath":"filePath","imageData":""} }).catch(ex => { }); ``` 获取多张图片Base 64 ``` ReadImageManager.readImages([{ filePath:'',// 手机本地存储路径 (如react-native-yuanxincamera) 必填 scale:1,//图片压缩比例,不改变大小的怀况下,最大值为1,最小值是0 width: 0,//默认是0 不做大小缩放处理 与height 相关 height:0,//默认是0 不做大小缩放处理 与width 相关 objectKey:'', //唯一id 。 },......]).then(result => { [ {"filePath":"filePath","imageData":""},......] }).catch(ex => { }); ```