convertFromImage method

Offset convertFromImage(
  1. Offset point,
  2. AnalysisImage img, {
  3. bool? flipXY,
})

this method is used to convert a point from an image to the preview according to the current preview size and the image size also in case of Android, it will flip the point if required

Implementation

Offset convertFromImage(
  Offset point,
  AnalysisImage img, {
  bool? flipXY,
}) {
  num imageDiffX;
  num imageDiffY;
  final shouldflipXY = flipXY ?? img.flipXY();
  if (Platform.isIOS) {
    imageDiffX = img.size.width - img.croppedSize.width;
    imageDiffY = img.size.height - img.croppedSize.height;
  } else {
    // Width and height are inverted on Android
    imageDiffX = img.size.height - img.croppedSize.width;
    imageDiffY = img.size.width - img.croppedSize.height;
  }
  var offset = (Offset(
            (shouldflipXY ? point.dy : point.dx).toDouble() - (imageDiffX / 2),
            (shouldflipXY ? point.dx : point.dy).toDouble() - (imageDiffY / 2),
          ) *
          scale)
      .translate(
    // If screenSize is bigger than croppedSize, move the element to half the difference
    (previewSize.width - (img.croppedSize.width * scale)) / 2,
    (previewSize.height - (img.croppedSize.height * scale)) / 2,
  );
  return offset;
}