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

Is There An Exposed Method To Programmatically Create The Filtered Image #47

Open
RalphMarvin opened this issue Sep 3, 2020 · 4 comments

Comments

@RalphMarvin
Copy link

What am trying to achieve is handle several images, I have managed to get all the images in page carousel, so when you swipe left and right you see all the images along side the filters. My problem right now, all this navigation is done inside a page (stateful widget). I cant seem to find a way of getting all the filtered images so i was wondering if there is an exposed method that can be called to return the filtered image.

@skkallayath
Copy link
Owner

Hi @RalphMarvin

You can use the following code to apply the filter on a file

Image applyFilterOnImageFile(Filter filter, File src) {
  Image image = decodeImage(src.readAsBytesSync());
  var pixels = image.getBytes();
  filter.apply(pixels, image.width, image.height);
  Image out = Image.fromBytes(image.width, image.height, pixels);
  return out;
}

if you want to save the filtered image to file (say at path destFileName),
use return new File(destFileName).writeAsBytesSync(encodeNamedImage(out, destFileName));

I will try to expose a function in the package in the upcoming release :)

@RalphMarvin
Copy link
Author

RalphMarvin commented Sep 7, 2020 via email

@RalphMarvin
Copy link
Author

RalphMarvin commented Sep 8, 2020

Hi @RalphMarvin

You can use the following code to apply the filter on a file

Image applyFilterOnImageFile(Filter filter, File src) {
  Image image = decodeImage(src.readAsBytesSync());
  var pixels = image.getBytes();
  filter.apply(pixels, image.width, image.height);
  Image out = Image.fromBytes(image.width, image.height, pixels);
  return out;
}

if you want to save the filtered image to file (say at path destFileName),
use return new File(destFileName).writeAsBytesSync(encodeNamedImage(out, destFileName));

I will try to expose a function in the package in the upcoming release :)

But with this approach, how can you get the selected filter ?

@skkallayath
Copy link
Owner

You are passing the selected filter to this method.

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

2 participants