【问题标题】:Difference between image and video in XFileXFile中图像和视频的区别
【发布时间】:2021-12-21 15:59:48
【问题描述】:

这是我的拍照方法:

handleTakePhoto() async {
 Navigator.pop(context);
 XFile? file = await ImagePicker()
    .pickImage(source: ImageSource.camera, maxWidth: 960, maxHeight: 675);
 setState(() {
   this.file = file;
   bytes = File(file!.path).readAsBytesSync();
 });
}

虽然这是用来拍摄视频的:

handleTakeVideo() async {
 Navigator.pop(context);
 XFile? file = await ImagePicker()
     .pickVideo(source: ImageSource.camera, maxDuration: const Duration(seconds: 10));
 setState(() {
   this.file = file;
   bytes = File(file!.path).readAsBytesSync();
 });
}

如您所见,它们实际上是相同的,但稍后在我的程序中,我需要知道文件是图像还是视频。我该怎么办?

【问题讨论】:

    标签: flutter dart flutter-dependencies imagepicker flutter-image


    【解决方案1】:

    他们拍摄照片和视频的方法可能相同,但图像文件和视频文件并不相同,包含不同的文件扩展名。图像文件可以是 .jpg、.jpeg 或 .png。您可以打印文件路径以自己查看这些。 print(file.path)。 查看此Flutter: Is the file an image or not? 以帮助区分它们。

    【讨论】:

      猜你喜欢
      • 2013-08-16
      • 1970-01-01
      • 2022-09-27
      • 2011-08-26
      • 2022-12-12
      • 1970-01-01
      • 2015-12-11
      • 2017-05-16
      • 1970-01-01
      相关资源
      最近更新 更多