I have a PNG image being sent from a DrawingView
in Android to a WCF service. The image is sent as a 32-bit and it has transparent background. I want to replace
This will draw onto a given color:
Bitmap Transparent2Color(Bitmap bmp1, Color target)
{
Bitmap bmp2 = new Bitmap(bmp1.Width, bmp1.Height);
Rectangle rect = new Rectangle(Point.Empty, bmp1.Size);
using (Graphics G = Graphics.FromImage(bmp2) )
{
G.Clear(target);
G.DrawImageUnscaledAndClipped(bmp1, rect);
}
return bmp2;
}
This makes use of the G.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
, which is the default. It blends the drawn image with the background according to the alpha channel of the drawn image.