Giter VIP home page Giter VIP logo

Comments (4)

NTMS2017 avatar NTMS2017 commented on August 29, 2024

I am keep getting this error:

Error:

flutter: ================= File: '/private/var/mobile/Containers/Data/Application/DBE50ECE-D66A-48C6-A1C3-1A15F602B300/tmp/image_crop_A2D9CA93-B387-4DE8-8269-E7CB040422F6-325-00000008F9BEEB4D.jpg'

flutter: Another exception was thrown: FileSystemException: Cannot open file, path = '/var/mobile/Containers/Data/Application/DBE50ECE-D66A-48C6-A1C3-1A15F602B300/Documents/File: '/private/var/mobile/Containers/Data/Application/DBE50ECE-D66A-48C6-A1C3-1A15F602B300/tmp/image_crop_A2D9CA93-B387-4DE8-8269-E7CB040422F6-325-00000008F9BEEB4D.jpg'' (OS Error: No such file or directory, errno = 2)

Code:

  //TODO: CROP IMAGE
  Future<void> _cropImage(BuildContext context) async {
    final scale = cropKey.currentState.scale;
    final area = cropKey.currentState.area;
    if (area == null) {
      // cannot crop, widget is not setup
      return;
    }

    // scale up to use maximum possible number of pixels
    // this will sample image in higher resolution to make cropped image larger
    final sample = await ImageCrop.sampleImage(
      file: _file,
      preferredSize: (3000 / scale).round(),
    );

    final file = await ImageCrop.cropImage(
      file: sample,
      area: area,
    );
    print("================= $file");
    setState(() {
      IDCardClass.frontImageFile = file.toString();
      widget.notifyParentFront();
      _corrping = false;
    });
    Navigator.pop(context);


from image_crop.

NTMS2017 avatar NTMS2017 commented on August 29, 2024

my main page widget widget.notifyParentFront(); code:

// TODO: (5) REFRESH FRONT
 refreshFront() async {
   final _directory = await getApplicationDocumentsDirectory();
   _appDocumentsDirectory = _directory.path;

   setState(() {
     if (IDCardClass.frontImageFile == null) {
       print("IDCardClass.frontImageFile looks like null");
       _frontImageFile = null;
     } else {
       //FILE
       _frontImageFile = new File(
           "${_appDocumentsDirectory + "/" + IDCardClass.frontImageFile}");
     }
   });
 }

from image_crop.

lykhonis avatar lykhonis commented on August 29, 2024

This is not a right place for dart questions.

  1. The issue you are having is that you are not using right path of the file: IDCardClass.frontImageFile = file.toString();. Instead of toString you should be using path property. That's assuming that IDCardClass.frontImageFile is a String.
  2. Once you cropped an image via ImageCrop.cropImage, it returns a file in the application directory. The application must have write permissions to local storage to copy this file to its final destination.

from image_crop.

leeyisoft avatar leeyisoft commented on August 29, 2024

I added the following code to solve the problem where the “ FileSystemException: Cannot open file”

       Future.delayed(Duration(milliseconds: 200)).then((value) {
          sample.delete();
          croppedFile.delete();
        });

参考 https://gitee.com/imboy-pub/imboy-flutter/blob/main/lib/component/helper/crop_image.dart

  Future<void> _crop(File originalFile) async {
    final crop = cropKey.currentState;
    final area = crop!.area;
    if (area == null) {
      //裁剪结果为空
      print('裁剪不成功');
    }

    await ImageCrop.requestPermissions().then((value) async {
      if (value) {
        final sample = await ImageCrop.sampleImage(
          file: originalFile,
          preferredSize: widget.preferredSize,
        );
        final croppedFile = await ImageCrop.cropImage(
          file: sample,
          area: crop.area!,
        );

        upload(croppedFile);
        Future.delayed(Duration(milliseconds: 200)).then((value) {
          sample.delete();
          croppedFile.delete();
        });
      } else {
        upload(originalFile);
      }
    });
  }

from image_crop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.