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

Convert image to gray scale #99

Open
dongmingsun opened this issue Sep 23, 2024 · 2 comments
Open

Convert image to gray scale #99

dongmingsun opened this issue Sep 23, 2024 · 2 comments

Comments

@dongmingsun
Copy link

Describe the solution you'd like
I want to convert the image to gray sacle. I've tried OverrideColor, OverrideFillColor and OverrideStrokeColor, but the effect is not satisfying. Just like convert the png image to gray scale, how to do it in SVGImage? Or is there any way that I can get the rendered image to modify it by myself?

@jogibear9988
Copy link
Member

SvgImage is no PNG image. It converts SVG Parts to WPF Drawing Objects.
Maybe code could be added, to convert each drawing color to a grayscale one. Needs to be tested.
If you need it, maybe you could create a pull request for this. I've no time to work on this.

@dongmingsun
Copy link
Author

dongmingsun commented Sep 23, 2024

For the moment, I managed to display the <svg> in gray scale, by using ShaderEffect based on a custom (but a simplified one, compared to others on the Internet) shader:

sampler2D input : register(s0);  

float4 main(float2 uv : TEXCOORD) : COLOR  
{  
    float4 color = tex2D(input, uv);  
    float gray = dot(color.rgb, float3(0.3, 0.59, 0.11));  
    return float4(gray, gray, gray, color.a);  
}

This approach satisfies my need. I'll consider to create a PR some time, maybe add a bool property to control the gray scale visual effect.

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