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

ColorFilter.matrix in Editor #629

Open
jj-gh opened this issue Oct 6, 2023 · 7 comments
Open

ColorFilter.matrix in Editor #629

jj-gh opened this issue Oct 6, 2023 · 7 comments
Assignees

Comments

@jj-gh
Copy link

jj-gh commented Oct 6, 2023

Content

Is there a way to add a matrix color filter to the image in the editor? I'm trying to create color filter presets and I would like them to be previewed in the editor.

@zmtzawqlp
Copy link
Member

@jj-gh
Copy link
Author

jj-gh commented Nov 16, 2023

take a look at. https://github.com/fluttercandies/flutter_image_editor#color-martix

Sorry if my question wasn't clear, what I meant is when ExtendedImage is in editor mode.

ExtendedImage.file(
    ...
    mode: ExtendedImageMode.editor,
    initEditorConfigHandler: (state) => EditorConfig(
        ...
        colorFilter: colorFilter,  // <-- It would be nice if this existed
        ....
    ),
    ...
)

I'm trying to do this:

output.mp4

@jj-gh jj-gh closed this as completed Nov 16, 2023
@jj-gh jj-gh reopened this Nov 16, 2023
@jj-gh
Copy link
Author

jj-gh commented Nov 16, 2023

Sorry, I accidentally closed the issue '>.<

@zmtzawqlp
Copy link
Member

I think you can add ColorFilter outside of ExtendedImage https://stackoverflow.com/questions/72139570/flutter-user-colorfiltered-to-dark-image-with-matrix

@jj-gh
Copy link
Author

jj-gh commented Nov 17, 2023

I think you can add ColorFilter outside of ExtendedImage https://stackoverflow.com/questions/72139570/flutter-user-colorfiltered-to-dark-image-with-matrix

A few issues with this:

  1. It applies the filter to the whole widget which includes the background, instead of just the image.
  2. The crop, rotation, and flip state will reset when the filter is toggled on/off.
  3. Zooming or cropping a high resolution image will make the UI very slow when the filter is on.
output.mp4

I came up with a solution for problem 1 and 2 by adding a ColorFilter parameter to EditorConfig class (editor_utils.dart), and then applying it in the build method of the ExtendedImageEditor widget (editor.dart)

@override
Widget build(BuildContext context) {
  ...
  Widget image = ExtendedRawImage(
    ...
  );

//======== THIS BLOCK ==========
  if (_editorConfig!.colorFilter != null)
    image = ColorFiltered(
      colorFilter: _editorConfig!.colorFilter!,
      child: image,
    );
//==============================
  ...
}

Here's the result, but problem 3 still remains.

output2.mp4

@karnadii
Copy link

karnadii commented Mar 13, 2024

you can do something like this, the filter will only affect the completed image, I don't know if it will work on editor though. it works with gesture mode.

 case LoadState.completed:
              return ImageFiltered(
                imageFilter: const ColorFilter.matrix(<double>[
                  ...[0.393, 0.769, 0.189, 0, 0],
                  ...[0.349, 0.686, 0.168, 0, 0],
                  ...[0.272, 0.534, 0.131, 0, 0],
                  ...[0, 0, 0, 1, 0]
                ]),
                child: state.completedWidget, 
              );
          }

@zhponng
Copy link

zhponng commented May 28, 2024

you can do something like this, the filter will only affect the completed image, I don't know if it will work on editor though. it works with gesture mode.

 case LoadState.completed:
              return ImageFiltered(
                imageFilter: const ColorFilter.matrix(<double>[
                  ...[0.393, 0.769, 0.189, 0, 0],
                  ...[0.349, 0.686, 0.168, 0, 0],
                  ...[0.272, 0.534, 0.131, 0, 0],
                  ...[0, 0, 0, 1, 0]
                ]),
                child: state.completedWidget, 
              );
          }

it only works on debug model, when i switch to release, the preview widget is blank.

But, when i changed ImageFiltered to container and set color to red, it works.

please somebody tell me why

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

4 participants