Image 如何将图像文件保存到gallery中的新文件夹?
我想在我从相机获取文件后将图像保存在图库中,如何创建新目录并保存我们从相机获取的图像文件Image 如何将图像文件保存到gallery中的新文件夹?,image,flutter,Image,Flutter,我想在我从相机获取文件后将图像保存在图库中,如何创建新目录并保存我们从相机获取的图像文件 Future getImageCamera() async { var imageFile = await ImagePicker.pickImage( source: ImageSource.camera, maxHeight: 20.0, maxWidth: 20.0); DateTime ketF = new DateTime.now(); String baru = "${ketF.ye
Future getImageCamera() async {
var imageFile = await ImagePicker.pickImage(
source: ImageSource.camera, maxHeight: 20.0, maxWidth: 20.0);
DateTime ketF = new DateTime.now();
String baru = "${ketF.year}${ketF.month}${ketF.day}";
//proses kompres
final temDirk = await getTemporaryDirectory();
final pathss = temDirk.path;
int rand = new math.Random().nextInt(100000);
//mengganti nama file
// String juduld = controllerJudul.text;
img.Image gambard = img.decodeImage(imageFile.readAsBytesSync());
img.Image gambarKecilx = img.copyResize(gambard,
700); //parameter awal adalah sumber gambar // parameter kedua ukuran width, hp=>1k
var kompresimg = new File("$pathss/image_$baru$rand.jpg")
..writeAsBytesSync(img.encodeJpg(gambarKecilx, quality: 95));
setState(() {
_gambar = kompresimg;
namafile = "image_$baru$rand.jpg";
});
您需要将图像保存到外部存储目录中,以便在gallery上显示图像。 获取外部存储目录,而不是获取临时目录
final directory = await getExternalStorageDirectory();
您需要提供对android/app/src/main
文件夹的AndroidManifest.xml
文件的权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
然后将文件写入路径
var kompresimg = new File("$myImagePath/image_$baru$rand.jpg")
..writeAsBytesSync(img.encodeJpg(gambarKecilx, quality: 95));
要获取文件数,只需将文件获取到列表中并检查列表的长度即可
var listOfFiles = await myImgDir.list(recursive: true).toList();
var count = countList.length;
那是工作。。而不是如何计算该文件夹中的文件数@Krishnakumar CNyes完成并添加这个img.Image images=img.decodeImage(kompresimg.readAsBytesSync());新文件('${testdir.path}/image_$baru$rand.jpg')…writeAsBytesSync(img.encodePng(images))@krishnakumarcn-我们如何编写视频文件?请建议。谢谢。无论文件类型如何,都可以重用此方法。确保提供了正确的文件扩展名@卡姆莱什
var listOfFiles = await myImgDir.list(recursive: true).toList();
var count = countList.length;