Sunday, March 26, 2023
HomeiOS Developmentandroid - Picture Compression in flutter of a Picture File

android – Picture Compression in flutter of a Picture File

[ad_1]

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.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments