개발/Flutter
이미지 사이즈 바꾸기
dev_caleb
2022. 3. 19. 12:47
728x90
File? getResizeImage(File originalImage){
Image image = decodeImage(originalImage.readAsBytesSync())!;
int standard = 800;
int width = image.width;
int height = image.height;
double ratio = width/height;
Image? resizedImage;
if(ratio>1) resizedImage = copyResize(image, width: min(width, standard), height: min(width.toDouble()/ratio, standard.toDouble()/ratio).toInt());
else resizedImage = copyResize(image, width: min(width*ratio, standard*ratio).toInt(), height: min(height, standard).toInt());
File newFile = File(originalImage.path);
newFile.writeAsBytesSync(encodeJpg(resizedImage, quality: 95),);
return newFile;
}
728x90