fix(camera): synchroniser le ratio de visée 3/4 avec le capteur natif et corriger le décalage du crop
This commit is contained in:
@@ -237,7 +237,22 @@ class _CropScreenState extends State<CropScreen> {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
_viewportSize = Size(constraints.maxWidth, constraints.maxHeight);
|
||||
_cropSize = math.min(constraints.maxWidth, constraints.maxHeight) * 0.95;
|
||||
|
||||
// FIX : On calcule d'abord la taille de la photo affichée avant de définir la taille du cadre vert !
|
||||
final imageAspect = _imageSize != null ? _imageSize!.width / _imageSize!.height : 1.0;
|
||||
final viewportAspect = _viewportSize.width / _viewportSize.height;
|
||||
|
||||
double displayWidth, displayHeight;
|
||||
if (imageAspect > viewportAspect) {
|
||||
displayWidth = _viewportSize.width;
|
||||
displayHeight = _viewportSize.width / imageAspect;
|
||||
} else {
|
||||
displayHeight = _viewportSize.height;
|
||||
displayWidth = _viewportSize.height * imageAspect;
|
||||
}
|
||||
|
||||
// On passe de 0.95 à 0.85 pour matcher parfaitement avec l'appareil photo !
|
||||
_cropSize = math.min(displayWidth, displayHeight)* 0.85;
|
||||
|
||||
if (_scale == 1.0 && _offset == Offset.zero && _rotation == 0.0) {
|
||||
_initializeImagePosition();
|
||||
@@ -333,6 +348,7 @@ class _CropScreenState extends State<CropScreen> {
|
||||
final imageAspect = _imageSize!.width / _imageSize!.height;
|
||||
final viewportAspect = _viewportSize.width / _viewportSize.height;
|
||||
|
||||
// 1. Calcul strict de la taille de l'image affichée en BoxFit.contain
|
||||
double displayWidth, displayHeight;
|
||||
if (imageAspect > viewportAspect) {
|
||||
displayWidth = _viewportSize.width;
|
||||
@@ -344,11 +360,15 @@ class _CropScreenState extends State<CropScreen> {
|
||||
|
||||
final minDisplayDim = math.min(displayWidth, displayHeight);
|
||||
|
||||
// 2. Calcul du scale initial basé sur la dimension de l'image (et non du viewport)
|
||||
_scale = widget.initialScale ?? (_cropSize / minDisplayDim);
|
||||
if (_scale < 1.0 && widget.initialScale == null) _scale = 1.0;
|
||||
|
||||
// 3. Réinitialisation propre de l'offset au centre de la zone d'affichage
|
||||
if (widget.initialOffset != null) {
|
||||
_offset = widget.initialOffset!;
|
||||
} else {
|
||||
_offset = Offset.zero; // Force l'image à se centrer parfaitement sur la croix verte
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user