1

How to change the BackColor of a transparent image to White using GDI objects without losing the content of the image.

When I tried to change it using the command this.image.backcolor, the content of the image is lost.

NASSER
  • 5,900
  • 7
  • 38
  • 57
user5271376
  • 156
  • 1
  • 10
  • 4
    Possible duplicate of [Replacing transparent background with white color in PNG images](http://stackoverflow.com/questions/27318549/replacing-transparent-background-with-white-color-in-png-images) – wingerse Nov 20 '15 at 11:32

4 Answers4

1

First you create a new image with the desired backcolor and the same size as your original image. Then you draw the original image on the new image using Graphics.DrawImage.

Dan Byström
  • 9,067
  • 5
  • 38
  • 68
1

create a bit map for image you want to change and use bitmap.clear(color u want);

Swetha
  • 523
  • 1
  • 4
  • 11
  • Answer does not help unless you read this answer: https://stackoverflow.com/a/27318979/694852 (bitmap does not have clear method). – Artemix Mar 17 '19 at 14:41
1

Even if you want to use CSS trick to do this, Here is the solution:-

CSS

.reverse{-webkit-filter: invert(100%); filter: invert(100%);}

HTML

<img src="src path" class="reverse">

Same way many other options are available in CSS. Hope this post will help you :).

Chetan Sharma
  • 334
  • 2
  • 11
0

Try this,

var newImage = new Bitmap(oldImage.Width, oldImage.Height);
using (var g = Graphics.FromImage(newImage))
{
    g.Clear(Color.White);
    g.DrawImage(oldImage, new Point(0, 0));        
}
NASSER
  • 5,900
  • 7
  • 38
  • 57