我编写的软件包的一部分采用二进制编码PDF,将其转换为位图,并将其保存到db中的blob中。我发现,虽然它在PDF格式的原始格式中没有立即可见,但在转换后的位图中完全可见的文档中有透明度。
我见过other posts命令行版本的imagemagick可以“平平”图像以删除透明层。这能用.NET包来做吗?如何在保存位图之前删除透明度?我需要保留它作为一个位图,因为它是一个普遍认可的格式,他们的标签打印机。
/// <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())
{
// 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);
}
}
}我尝试过用不同的方法来调整透明层,或者对背景着色,但都没有成功。
//image.BackgroundColor = new ColorMono(false);
//image.TransparentChroma(new MagickColor(0, 0, 0), new MagickColor(0, 0, 0));
//image.TransparentChroma(new ColorRGB(0, 0, 0), new ColorRGB(65535, 65535, 65535));
//image.BackgroundColor = new MagickColor("#fff");
//image.BackgroundColor = new MagickColor("#ffffff");
//image.BackgroundColor = new MagickColor("#ffffffffffff");
//image.Settings.BackgroundColor.A = 0;发布于 2018-11-01 00:57:07
尝试删除Alpha组件,并根据输出设置背景色:
image.Alpha(AlphaOption.Remove);https://stackoverflow.com/questions/53093839
复制相似问题