openCamera static method
Future<Media?>
openCamera({
- CameraMimeType cameraMimeType = CameraMimeType.photo,
- CropConfig? cropConfig,
- int compressSize = 500,
返回拍摄的图片或视频的信息 Return information of the selected picture or video
cameraMimeType CameraMimeType.photo为拍照,CameraMimeType.video 为录制视频 CameraMimeType.photo is a photo, CameraMimeType.video is a video
cropConfig 裁剪配置(视频不支持裁剪和压缩,当选择视频时此参数无效) Crop configuration (video does not support cropping and compression, this parameter is not available when selecting video)
compressSize 拍照后(录制视频时此参数无效)的忽略压缩大小,当图片大小小于compressSize时将不压缩 单位 KB Ignore compression size after selection, will not compress unit KB when the image size is smaller than compressSize
Implementation
static Future<Media?> openCamera({
CameraMimeType cameraMimeType: CameraMimeType.photo,
CropConfig? cropConfig,
int compressSize: 500,
}) async {
String mimeType = "photo";
if (cameraMimeType == CameraMimeType.video) {
mimeType = "video";
}
bool enableCrop = false;
int width = 1;
int height = 1;
if (cropConfig != null) {
enableCrop = cropConfig.enableCrop;
width = cropConfig.width <= 0 ? 1 : cropConfig.width;
height = cropConfig.height <= 0 ? 1 : cropConfig.height;
}
Color uiColor = UIConfig.defUiThemeColor;
final Map<String, dynamic> params = <String, dynamic>{
'galleryMode': "image",
'showGif': true,
'uiColor': {
"a": 255,
"r": uiColor.red,
"g": uiColor.green,
"b": uiColor.blue,
"l": (uiColor.computeLuminance() * 255).toInt()
},
'selectCount': 1,
'showCamera': false,
'enableCrop': enableCrop,
'width': width,
'height': height,
'compressSize': compressSize < 50 ? 50 : compressSize,
'cameraMimeType': mimeType,
};
final List<dynamic>? paths =
await _channel.invokeMethod('getPickerPaths', params);
if (paths != null && paths.length > 0) {
Media media = Media();
media.thumbPath = paths[0]["thumbPath"];
media.path = paths[0]["path"];
media.galleryMode = GalleryMode.image;
return media;
}
return null;
}