|
[C#]
using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/sam-schooler-E9aetBe2w40-unsplash.jpg"))) {
bm.MakeTransparent(Color.White);
using (Bitmap bm2 = new Bitmap(bm.Width, bm.Height)) {
bm2.SetResolution(bm.VerticalResolution, bm.HorizontalResolution);
using (Graphics gr = Graphics.FromImage(bm2)) {
gr.Clear(Color.Green);
gr.DrawImage(bm, bm2.Bounds);
}
bm2.Save(Server.MapPath("IG8_Bitmap_MakeTransparent.jpg"));
}
}
The code here selects all the white pixels in the image and
replaces them with green ones before saving the final output as a
JPEG. The final output is shown below.

sam-schooler-E9aetBe2w40-unsplash.jpg

IG8_Bitmap_MakeTransparent.jpg
|