getEditedImage method
Implementation
Future<Uint8List> getEditedImage() async {
print('kdfnjkdgngk');
if (kIsWeb) {
return _saveImageOnWeb(renderRepaintKey: _renderRepaintKey);
}
// final locationData = await .call();
// Need to use this library as the default file lib ignores the exif data.
final img = await FlutterExifRotation.rotateImage(path: imageFile.path);
if (img.existsSync()) {
debugPrint('InspectionCamera: File exists');
final i = image.decodeImage(await img.readAsBytes())!;
image.Image orientedImage;
// Rotate the image to have the text on a specific angle.
if (_angleForText != 0) {
orientedImage = image.copyRotate(
i,
angle: _angleForText,
);
} else {
orientedImage = i;
}
final dateSting = DateFormat('dd MMM, yyyy HH:mm').format(dateTime);
final dateStringWidth = getTextSize(dateSting).width;
image.drawString(
orientedImage,
font: image.arial48,
// x: orientedImage.width ~/ 4,
// y: orientedImage.height - 48,
x: (orientedImage.width - dateStringWidth - 320).toInt(),
y: orientedImage.height - 120,
dateSting,
// color: image.ColorUint8.rgba(0xff, 0xff, 0xff, 0xff),
color: image.ColorRgb8(225, 19, 40),
);
final locationSting =
'${locationData.latitude}, ${locationData.longitude}';
final locationStringWidth = getTextSize(locationSting).width;
// var dateTimeNow = DateTime.now();
// var date = DateTime(dateTimeNow.year, dateTimeNow.month, dateTimeNow.day)
// .toString()
// .replaceAll("00:00:00.000", "");
// var time =
// "${dateTimeNow.hour.toString().padLeft(2, '0')}:${dateTimeNow.minute.toString().padLeft(2, '0')}:${dateTimeNow.second.toString().padLeft(2, '0')}";
// String dateTimes = "$time $date";
final drawString = image.drawString(
orientedImage,
font: image.arial48,
// x: (2 * orientedImage.width) ~/ 3,
x: (orientedImage.width - locationStringWidth - 400).toInt(),
y: orientedImage.height - 70,
locationSting,
// color: image.ColorUint8.rgba(0xff, 0xff, 0xff, 0xff),
color: image.ColorRgb8(225, 19, 40),
);
// if(isPortrait){
// image.Image orientedImage1 = image.copyRotate(drawString, 90);
// }
image.Image originalOrientation;
// Rotate the image to its original angle.
if (_angleForText != 0) {
originalOrientation = image.copyRotate(
drawString,
angle: 360 - _angleForText,
);
} else {
originalOrientation = drawString;
}
final bytes = Uint8List.fromList(
image.encodeJpg(originalOrientation, quality: 100),
);
await File(imageFile.path).delete();
return bytes;
} else {
throw Exception('No file.');
}
}