Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleCameraPicker = () => {
ImagePicker.openCamera({
mediaType: 'photo',
loadingLabelText: '请稍候...',
}).then(image => {
NimSession.sendImageMessages(image.path, 'myName')
})
// ImagePicker.openPicker({
// mediaType:'video',
// loadingLabelText:'请稍候...'
// }).then((video) => {
// console.log(video);
// NimSession.sendVideoMessage(video.path, 'duration', 'width', 'height', 'displayName');
// });
}
onLocation = (coordinate) => {
_openCamera() {
this.setState({ modalVisible: false });
// ImagePicker.launchCamera(options, (response) => {
// // uri (on android)
// // const source = { uri: response.uri, isStatic: true };
// const source = { uri: 'data:image/jpeg;base64,' + response.data, isStatic: true };
// this.setState({
// avatarSource: source,
// });
// });
ImageCropPicker.openCamera({
width: 500,
height: 500,
cropping: true,
cropperTintColor: '#453d4b'
}).then(image => {
this.setState({
avatarSource: image.path,
});
});
}
export const getCameraMediaObjectMultiple = async (options = {}): Promise => {
try {
const mediaObject: IPickerImage | IPickerImage[] = await ImagePicker.openCamera({
...DEFAULT_CAMERA_OPTIONS,
...options,
});
return [mediaObject as IPickerImage];
} catch (ex) {
console.log('getCameraMediaObjectMultiple error', ex);
return [];
}
};
openPicker = async (isCamera: boolean) => {
const options = {
cropping: this.props.circleCropping,
mediaType: 'photo',
cropperCircleOverlay: this.props.circleCropping,
compressImageQuality: 0.4,
includeBase64: true,
};
try {
const result = isCamera ?
await ImagePicker.openCamera(options)
:
await ImagePicker.openPicker(options);
if (result.data) {
this.props.onImageChosen(result.data, result.mime);
}
} catch (error) {
if (error.code !== 'E_PICKER_CANCELLED') {
Alert.alert(i18n.t('error.noCamera'));
}
}
};
function openCamera (options) {
const {success, fail, complete} = options
return ImagePicker.openCamera({}).then(image => {
const result = {
tempFilePaths: [image.path],
tempFiles: [
{
path: image.path,
size: image.size
}]
}
const data = Object.assign({}, result, res)
success && success(data)
complete && complete(data)
return data
})
}
onOpenCameraPress() {
ImagePicker.openCamera({
width: Constants.UPLOAD_POST_PICTURE_SIZE,
height: Constants.UPLOAD_POST_PICTURE_SIZE,
cropping: true,
})
.then((image) => {
const imageSource = extractImageSource(image);
this.setState({
imageFile: image,
imageSource,
});
});
}
_handleOpenCamera = action => {
ImagePicker.openCamera({
includeBase64: true,
})
.then(image => {
this._handleMediaOnSelected(image, action);
})
.catch(e => {
this._handleMediaOnSelectFailure(e);
});
};
successAddAnotherTrashPoint = async () => {
const image = await ImagePicker.openCamera({
compressImageQuality: 0.2,
cropping: true,
includeBase64: true,
});
const { width, height, data, path } = image;
const uri = path;
const base64 = data;
const thumbnailBase64 = await ImageService.getResizedImageBase64({
uri,
width,
height,
});
var newPosition;
if (Platform.OS === 'ios') {
newPosition = this.actualCoords
openPicker = async (isCamera: boolean) => {
const options = {
cropping: this.props.circleCropping,
mediaType: 'photo',
cropperCircleOverlay: this.props.circleCropping,
compressImageQuality: 0.4,
includeBase64: true,
};
try {
const result = isCamera ?
await ImagePicker.openCamera(options)
:
await ImagePicker.openPicker(options);
if (result.data) {
this.props.onImageChosen(result.data, result.mime);
}
} catch (error) {
if (error.code !== 'E_PICKER_CANCELLED') {
Alert.alert(i18n.t('error.noCamera'));
}
}
};
function takePhoto({
takePhotoOptions,
uploadAction
}) {
ImagePicker.openCamera(takePhotoOptions).then(image => {
uploadAction && uploadAction(image);
}).catch(e => {
if (e.code === 'E_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR') {
AlertIOS.alert('提示', MESSAGES[e.code]);
} else if (e.code === 'E_PICKER_NO_CAMERA_PERMISSION') {
goToAppSettings(MESSAGES[e.code]);
}
});
}