Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I am creating a windows application that can take product template (T-Shirt) and paste customer logo on that. I need to change color of product Template & logo as per the request of the customer.

I have googled but din't get any proper resolutions.

What I have tried:

private void button1_Click(object sender, EventArgs e)
        {
            
            
           string template1 = @"D://shailendra//CurrentProject//Dubow//aws_live//Templates//ProductTemplate//18500_Front.jpg";
            pictureBox1.Image = Image.FromFile(template1);

            
            using (MagickImage image = new MagickImage(template1))
            {
                // Fill the image with a transparent background
                image.FloodFill(MagickColors.None, 0, 0);

                // Change all the pixels that are not transparent to yellow.
                image.InverseOpaque(MagickColors.None, MagickColors.Blue);
                image.
                //image.CopyPixels()

                // Change the transparent pixels to white.
                image.ColorAlpha(MagickColors.White);

                image.Write("test.png");
                pictureBox2.Image = Image.FromFile(image.FileName);


            }
Posted
Updated 15-Jan-19 4:24am
Comments
Patel Shailendra 15-Jan-19 8:25am    
This will make my product template as blue but it's not that i required. Its create inverse image

MagickImage has a method which changes color called opaqueImage
MagickImage[^]

An important item to account for when using this is that the colored pixels you want to change may not all have the EXACT same RGB values, especially when you are dealing with jpegs that have lossy compression schemes. There are a couple of options on how to overcome this.

The first would be to change the "base" image type from JPG to a PNG image which can be set to a non-lossy compression scheme. You could then roto-scope the image to "flatten" the colors to one exact color to change.

Another option would be to use a property within MagickImage which allows a deviation to be set to the color match, it is called ColorFuzz, and allows you to enter in a percentage of from the original color to look for. I did find a thread on Stack Overflow that covered this very thing
c# - Cannot replace color with Magick.Net - Stack Overflow[^]
 
Share this answer
 
Access the bitmap and its pixels and get/set them to the new color. This is explained int the article Work with Bitmaps Faster in C#. Use the logo as a transparent overlay image.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900