sawankumarbundelkhandi / edge_detection

This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.
https://pub.dev/packages/edge_detection
Apache License 2.0
242 stars 242 forks source link

After loading and cropping an image from gallery it doesn't save the cropped image in the path passed but if I shot an image it works just fine #134

Open Bogghi opened 1 year ago

Bogghi commented 1 year ago

Hi, I'm having an issue with saving the image cropped after loading it from the gallery. Basically it load the image just fine in the UI and it crop correctly but when it comes to saving the cropped image it fails but it doesn't throw any exception. Im running an ipad mini gen 5 with ipadOS 16.3.1.

Here's my steps:

 Future<void> getImage(context) async{
    bool isCameraGranted = await Permission.camera.request().isGranted;
    late bool success;

    if(!isCameraGranted){
      isCameraGranted = await Permission.camera.request() == PermissionStatus.granted;
    }

    if(!isCameraGranted)
      return;

    final String imagePath = await getPath();
    final String compressedPath = await getPath();

    success = await EdgeDetection.detectEdge(imagePath,
      canUseGallery: true,
      androidScanTitle: 'Scanning', // use custom localizations for android
      androidCropTitle: 'Crop',
      androidCropBlackWhiteTitle: 'Black White',
      androidCropReset: 'Reset',
    );

    // success = await EdgeDetection.detectEdgeFromGallery(
    //   imagePath
    // );
    print(File(imagePath).lengthSync());

    if(!success)
      return;

    await FlutterImageCompress.compressAndGetFile(
      imagePath,
      compressedPath,
      quality: 5
    );

    setState(() {
      scannedFile.add(compressedPath);
    });
  }

at the print i get this error, if i remove the print i get an error from the compress signaling that the image doesn't exist.

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '/var/mobile/Containers/Data/Application/681E693B-504B-46E2-8D29-C0333643FE0E/Library/Caches/79.jpeg' (OS Error: No such file or directory, errno = 2)
#0      _File.throwIfError (dart:io/file_impl.dart:635:7)
#1      _File.lengthSync (dart:io/file_impl.dart:377:5)
#2      _BrchdocDocumentCatcherState.getImage (package:app_rm_nca/page/brchdoc/brchdoc_document_capturer.dart:143:27)

when i shoot an image i get this values, witch is correct and it works just fine

flutter: 1558066

when trying to use the EdgeDetection.detectEdgeFromGallery i get the same errors.

Has anyone encountered a similar issue? I'm stack not knowing what to do or how to work around this issue.

Best regards guys