本文介绍了重命名文件/图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 image_picker:^ 0.6.2 + 3 包从画廊中挑选图像/拍照.

I am picking a image from gallery/taking a photo using image_picker: ^0.6.2+3 package.

File picture = await ImagePicker.pickImage(
  maxWidth: 800,
  imageQuality: 10,
  source: source, // source can be either ImageSource.camera or ImageSource.gallery
  maxHeight: 800,
);

我得到 picture.path

/Users/[ some path ]/tmp/image_picker_A0EBD0C1-EF3B-417F-9F8A-5DFBA889118C-18492-00001AD95CF914D3.jpg

/Users/[some path]/tmp/image_picker_A0EBD0C1-EF3B-417F-9F8A-5DFBA889118C-18492-00001AD95CF914D3.jpg

现在我想将图像重命名为 case01wd03id01.jpg

Now I want to rename the image to case01wd03id01.jpg

如何重命名?我在官方文档中找不到它.

How can I rename it? I could not find it in official docs.

推荐答案

首先导入路径包.

import 'package:path/path.dart' as path;

然后创建一个新的目标路径来重命名文件.

Then create a new target path to rename the file.

File picture = await ImagePicker.pickImage(
        maxWidth: 800,
        imageQuality: 10,
        source: ImageSource.camera,
        maxHeight: 800,
);
print('Original path: ${picture.path}');
String dir = path.dirname(picture.path);
String newPath = path.join(dir, 'case01wd03id01.jpg');
print('NewPath: ${newPath}');
picture.renameSync(newPath);

这篇关于重命名文件/图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:44