首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Imagemagick.NET去除透明度

用Imagemagick.NET去除透明度
EN

Stack Overflow用户
提问于 2018-11-01 00:53:59
回答 1查看 1.8K关注 0票数 3

我编写的软件包的一部分采用二进制编码PDF,将其转换为位图,并将其保存到db中的blob中。我发现,虽然它在PDF格式的原始格式中没有立即可见,但在转换后的位图中完全可见的文档中有透明度。

我见过other posts命令行版本的imagemagick可以“平平”图像以删除透明层。这能用.NET包来做吗?如何在保存位图之前删除透明度?我需要保留它作为一个位图,因为它是一个普遍认可的格式,他们的标签打印机。

代码语言:javascript
复制
    /// <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);
            }
        }
    }

我尝试过用不同的方法来调整透明层,或者对背景着色,但都没有成功。

代码语言:javascript
复制
            //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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-01 00:57:07

尝试删除Alpha组件,并根据输出设置背景色:

代码语言:javascript
复制
image.Alpha(AlphaOption.Remove);
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53093839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档