How can I make an image transparent? #1272
Answered
by
JimBobSquarePants
ThatRendle
asked this question in
Q&A
-
I've got an image created from a document with a white background, in PNG format. I guess there must be some way to replace the white with transparent, but I don't know where to start. |
Beta Was this translation helpful? Give feedback.
Answered by
JimBobSquarePants
Jul 13, 2020
Replies: 1 comment 6 replies
-
There's a few ways:
I think 3 is probably the easiest way to go, bear in mind though that using var image = Image.Load(...);
float threshold = 0..1F;
Color sourceColor = Color.White;
Color targetColor = Color.Transparent;
var brush = new RecolorBrush(sourceColor, targetColor, threshold);
image.Mutate(x => x.Fill(brush));
image.Save(...); |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
ThatRendle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a few ways:
Color.White
withColor.Transparent
.ImageSharp.Drawing
package andRecolorBrush
which takes source and target colors. You then pass that to theFill
method.I think 3 is probably the easiest way to go, bear in mind though that
ImageSharp.Drawing
is a beta and subject to change.