In continuation from a previous SO post here I've gone from being able to remove the transparency from a PDF conversion, to not being able to adjust the background color of the conversion. I've tried everything that I can find on the Imagemagick.NET github docs. I need to ensure that ANY image that is passed through this software package has a non transparent white background.
/// <summary>
/// Write image data from a pdf file to a bitmap file
/// </summary>
/// <param name="imgData"></param>
private static void convertPdfToBmp(ImageData imgData)
{
MagickReadSettings settings = new MagickReadSettings();
// Settings the density to 600 dpi will create an image with a better quality
settings.Density = new Density(600);
using (MagickImageCollection images = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
images.Read(imgData.pdfFilePath, settings);
// Create new image that appends all the pages horizontally
using (IMagickImage image = images.AppendVertically())
{
// Remove the transparency layers and color the background white
image.Alpha(AlphaOption.Remove);
int aval = image.Settings.BackgroundColor.A = 0;
int rval = image.Settings.BackgroundColor.R = 0;
int bval = image.Settings.BackgroundColor.G = 0;
int gval = image.Settings.BackgroundColor.B = 0;
// Convert the image to a bitmap
image.Format = MagickFormat.Bmp;
// Delete any old file
if (File.Exists(imgData.bmpFilePath))
{
File.Delete(imgData.bmpFilePath);
}
// Save result as a bmp
image.Write(imgData.bmpFilePath);
}
}
}
In the code above, if I set any of the 4 channels image.Settings.BackgroundColor
to a different color, it has no affect on the image. If I use image.BackgroundColor
it has no affect on the image. What am I missing?
Note: in the above code I am setting the colors to black to verify the code is working. I've tried other colors as well for giggles.