I’m saving a an image with a transparent background to jpeg.
Is there a way to convert the transparent pixels to a certain color without iterating on all the pixels?
This is the code I’m using (also – is the first line a common way to do it? are there different encoders?)
public void SaveImage(Bitmap image, string path)
{
var encoder = ImageCodecInfo.GetImageEncoders().FirstOrDefault(c => c.MimeType == "image/jpeg");
var encodeParams = new EncoderParameters(1);
encodeParams.Param[0] = new EncoderParameter(Encoder.Quality, (long)100);
image.Save(path, encoder, encodeParams);
}
The usual solution is to make a bitmap image with your desired background color, render your image to it, and save/convert this bitmap as an image.
Check Graphics.FromImage. This will give you a Graphics rendering object for a bitmap.