c# - Save non-transparent image from a PictureBox with transparent images -
i have picturebox lots of transparent png's drawn into...
now i'd save content of picturebox file, without transparency.
how can this?
i have tried remove transparency image this, didn't work, still got transparent image after save.
... removetransparency(picturebox.image).save(savefiledialog.filename); private bitmap removetransparency(image transparentimage) { bitmap src = new bitmap(transparentimage); bitmap newimage = new bitmap(src.size.width, src.size.height); graphics g = graphics.fromimage(newimage); g.drawrectangle(new pen(new solidbrush(color.white)), 0, 0, newimage.width, newimage.height); g.drawimage(src, 0, 0); return newimage; }
you may cycle through pixel (please not using getpixel/setpixel) change color or may create bitmap same size, create graphics context image, clear image favorite background color , draw image on (so transparent pixels replaced background color).
example
did this?
public static bitmap repaint(bitmap source, color backgroundcolor) { bitmap result = new bitmap(source.width, source.height, pixelformat.format32bppargb); using (graphics g = graphics.fromimage(result)) { g.clear(backgroundcolor); g.drawimage(source, new rectangle(0, 0, source.width, source.height)); } return result; }
Comments
Post a Comment