如何防止 ImageMagick.NET 在写入时更改颜色空间

问题描述 投票:0回答:1

尝试打开图像,设置其分辨率并保存它,但我遇到了一个问题,即在我没有任何输入的情况下修改

ColorSpace

输入图像是一张空白的sRGB/8图像,创建后检查

img.ColorSpace
显示
sRGB
,但是在设置密度,将图像写入磁盘并打开输出后,
ColorSpace
设置为
Gray
.

using (var img = new MagickImage(inputImagePath))
{
    img.Density = new Density(parameters.HorizontalResolution, parameters.VerticalResolution);
    img.Write(outputImagePath);
    // img.ColorSpace is sRGB
}

using (var imgCheck = new MagickImage(outputImagePath))
{
    // imgCheck.ColorSpace is gray
}

下游代码要求输出图像的色彩空间与输入图像的色彩空间相同。是否有

MagickImage.Write()
的参数可以保留颜色空间?

imagemagick imagemagick.net
1个回答
0
投票

在回顾这个相关问题后:ImageMagick: convert keeps changing the colorspace to Gray.如何保留 sRGB 色彩空间? 如果图像的格式设置为

MagickFormat.Png
,并且其内容为灰度,则 ImageMagick 会将色彩空间设置为灰度。

using (var img = new MagickImage(inputImagePath))
{
    img.Density = new Density(parameters.HorizontalResolution, parameters.VerticalResolution);
    img.Write(outputImagePath, MagickFormat.Png00);
    // img.ColorSpace is sRGB
}

using (var imgCheck = new MagickImage(outputImagePath))
{
    // imgCheck.ColorSpace is gray
}

Write()
上手动设置 MagickFormat 到
Png00
保留输入的颜色空间和每像素位数设置。

© www.soinside.com 2019 - 2024. All rights reserved.