Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter from File & return File #49

Open
loic-hamdi opened this issue Oct 8, 2020 · 0 comments
Open

Filter from File & return File #49

loic-hamdi opened this issue Oct 8, 2020 · 0 comments

Comments

@loic-hamdi
Copy link

loic-hamdi commented Oct 8, 2020

Hi,

I am using https://pub.dev/packages/multi_image_picker/ to transform List<Asset> to List<File>
This list is generated as below :

final temp = await Directory.systemTemp.createTemp();
List<File> images = List<File>();
 for (int i = 0; i < assets.length; i++) {
    final data = await assets[i].getByteData();
    images.add(await File('${temp.path}/img$i').writeAsBytes(
      data.buffer.asUint8List(
        data.offsetInBytes, data.lengthInBytes)));
}

From that list, I then display the pictures in a carousel allowing the user to crop the picture and/or apply a filter.

I am struggling to setup the filter example.

I woud like to get the File > apply the filter > replace the previous File with the new one and then setState to update the carousel image.

Where are my mistakes there please ?

  Future<File> applyFilterOnImageFileSaveToFile(Filter filter, File src) async {
    imageLib.Image image = imageLib.decodeImage(src.readAsBytesSync());
    var pixels = image.getBytes();
    filter.apply(pixels, image.width, image.height);
    imageLib.Image out =
        imageLib.Image.fromBytes(image.width, image.height, pixels);
    File destinationFile = new File(src.path)..createSync(recursive: true);
    File(destinationFile.path).writeAsBytesSync(out.getBytes());
    return destinationFile;
  }

GestureDetector(
                       onTap: () async {
                          File newFileWithFilterApplied = await applyFilterOnImageFileSaveToFile(AddictiveRedFilter(), imagesFromMultiPickerReadyForCropping[indexCurrentPhotoCarouselIndex - 1]);
                          setState(() {
                            imagesFromMultiPickerReadyForCropping[indexCurrentPhotoCarouselIndex - 1] = newFileWithFilterApplied;
                          });
                        },
                        },
                      ),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant