0

In this example, using C# how can I compare the white image with the black image to get a transparent background image ?

enter image description here

The problem here is in this code, comparing the white picture with the black picture, and returning the background gray picture.

var image = new Bitmap(this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);
var rect = new Rectangle(0, 0, this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);

Graphics graphics = Graphics.FromImage(image);
graphics.DrawImage(this.pictureBox1.Image, 0, 0);

var waterMarkImage = new Bitmap(this.pictureBox2.Image.Width, this.pbox_2resim.Image.Height);
for (int y = 0; y < waterMarkImage.Height; y++)
{
    for (int x = 0; x < waterMarkImage.Width; x++)
    {
        var color = (this.pictureBox2.Image as Bitmap).GetPixel(x, y);
        color = Color.FromArgb(50, color.R, color.G, color.B);
        waterMarkImage.SetPixel(x, y, color);
    }
}

graphics.DrawImage(waterMarkImage, rect);

this.pictureBox3.Image = image;
Johnny Mopp
  • 12,641
  • 5
  • 36
  • 62
  • That looks difficult because of the semi-transparent parts. But to just make black transparent, compare `color` to black. If equal set alpha to 0, else set alpha to 100. – Johnny Mopp Apr 01 '20 at 19:51
  • Does this answer your question? [“Diff” an image using ImageMagick](https://stackoverflow.com/questions/5132749/diff-an-image-using-imagemagick) – Maytham Fahmi Apr 01 '20 at 19:55
  • Does this link help you?https://stackoverflow.com/questions/4416934/c-how-to-make-a-picture-background-transparent – Soheila Tarighi Apr 01 '20 at 20:17
  • Your problem is poorly defined. Please provide a good [mcve] showing what you've tried, making sure to include useful sample inputs, and explain exactly how you envision your algorithm dealing with transparency where the background to be removed is also visible through transparent areas that are not to be removed (as it appears to be the case in your example). – Peter Duniho Apr 02 '20 at 00:36

0 Answers0