Skip to content

Make part of an image transparent. #147

Answered by Surfrat
Surfrat asked this question in Q&A
Discussion options

You must be logged in to vote

I figured out a solution:

        [Test]
        [Explicit]
        public void TestMakeImageBackgroundTransparentForShirt1()
        {
            string fileName = "DressMe.Tests.Images.Shirt1.jpg";
            Stream stream = GetEmbeddedImage(fileName);

            if (stream != null)
            {
                Image image = Image.Load<Rgba32>(stream);

                float threshold = 0.1F;
                Color sourceColor = Color.White;
                Color targetColor = Color.Transparent;
                RecolorBrush brush2 = new RecolorBrush(sourceColor, targetColor, threshold);

                image.Mutate(i => i.Clear(brush2));

                SaveToPng(_testImageFilenam…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@JimBobSquarePants
Comment options

@Surfrat
Comment options

@JimBobSquarePants
Comment options

@Surfrat
Comment options

Answer selected by Surfrat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants