Remove transparency in images with C#

前端 未结 6 874
野性不改
野性不改 2020-12-16 18:26

does anyone know a smooth / fast way of removing transparency from e.g. pngs/tiffs etc and replacing it with a white background?

Basically what I need this for is I

6条回答
  •  不知归路
    2020-12-16 18:43

    You could create a bitmap the same size as the png, draw a white rectangle and then draw the image on top of it.

    void RemTransp(string file) {
        Bitmap src = new Bitmap(file);
        Bitmap target = new Bitmap(src.Size.Width,src.Size.Height);
        Graphics g = Graphics.FromImage(target);
        g.DrawRectangle(new Pen(new SolidBrush(Color.White)), 0, 0, target.Width, target.Height);
        g.DrawImage(src, 0, 0);
        target.Save("Your target path");
    }
    

提交回复
热议问题