magicuts coupons december 2013 sportcompactonly coupon code name all the gifts of the holy spirit fandango coupon code august 2015 frames broker promotion coupon newport 100 carton coupons
Sunday, November 20, 2022
HomeiOS Developmentandroid - Picture Compression in flutter of a Picture File

android – Picture Compression in flutter of a Picture File


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.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments