Issue
Future<void> saveLocalStorage(File image) async {
// get file format of the image
String fileFormat = image.path.split('.').last; // jpg
// get path for applications directory
final directory = await getApplicationDocumentsDirectory();
// January 1st, 1970 at 00:00:00 UTC is referred to as the Unix epoch.
int time = DateTime.now().millisecondsSinceEpoch;
// saving image into applications document directory
image.copy('${directory.path}/$time.$fileFormat');
}
This is the code that I am currently using to save an image File. But before saving, I wish to compress the Image. I found a solution using the image package but its documentation itself says that it isn't fast enough so I don't prefer using it. Another solution was using the image_picker whose example code is:
ImagePicker imagePicker = ImagePicker();
PickedFile compressedImage = await imagePicker.getImage(
source: ImageSource.camera,
imageQuality: 85,
);
I tried using the same example but the source attribute doesn't File as its value so I am unable to do the compression. Please suggest some solution to get this done.
Solution
Use this library : Flutter Image Compress
Compresses image as native plugin (Obj-C/Kotlin)
or unknown reasons, image compression in Dart language is not efficient, even in release version.
Answered By - Narendra_Nath
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.