我正在使用ImageMagick/ghostscript处理所有*.eps
文件,并获得每个图像的颜色配置文件并显示结果。但我得到的结果与CMYK的灰度,RGB, CMYK相同。
我不知道我在哪里做错了,也不知道哪个属性会得到确切的结果。
c#代码
namespace ConsoleApplication3
{
using System;
using System.IO;
using ImageMagick;
class Program
{
static void Main(string[] args)
{
foreach (var epsFile in Directory.GetFiles(@"c:tmpeps", "*.eps"))
{
using (var image = new MagickImage())
{
image.Read(epsFile);
Console.WriteLine("file: {0} color space: {1}", epsFile, image.ColorSpace);
}
}
}
}
}
预期结果
file: c:tmpepsa.eps color space: CMYK
file: c:tmpepsb.eps color space: CMYK
file: c:tmpepsc.eps color space: CMYK
file: c:tmpepscircle.eps color space: sRGB
file: c:tmpepsd.eps color space: CMYK
file: c:tmpepse.eps color space: CMYK
file: c:tmpepsf.eps color space: Grayscale
file: c:tmpepsfootball_logo.eps color space: sRGB
file: c:tmpepsfsu_logo.eps color space: sRGB
file: c:tmpepsg.eps color space: CMYK
file: c:tmpepsicam_logo.eps color space: sRGB
Press any key to continue . . .
但是当前的结果是
file: c:tmpepsa.eps color space: CMYK
file: c:tmpepsb.eps color space: CMYK
file: c:tmpepsc.eps color space: CMYK
file: c:tmpepscircle.eps color space: CMYK
file: c:tmpepsd.eps color space: CMYK
file: c:tmpepse.eps color space: CMYK
file: c:tmpepsf.eps color space: CMYK
file: c:tmpepsfootball_logo.eps color space: CMYK
file: c:tmpepsfsu_logo.eps color space: CMYK
file: c:tmpepsg.eps color space: CMYK
file: c:tmpepsicam_logo.eps color space: CMYK
Press any key to continue . . .
一个简单的解决方案是重写用于设置颜色空间的PostScript操作符,如setgbcolor, setgray, setcmykcolor和setcolorspace。
,
/system_setrgbcolor /setrgbcolor load def
/setrgbcolor {
(EPS file used setrgbcolor) == flush
system_setrgbcolor
}bind def
或者更复杂的解决方案:
/MyDict 10 dict def
/MyDict begin
/UsedRGB false def
/UsedGray false def
/UsedCMYK false def
end
/system_setrgbcolor /setrgbcolor load def
/setrgbcolor {
/MyDict /UsedRGB get not {
(EPS file used setrgbcolor) == flush
/MyDict /UsedRGB true put
} if
system_setrgbcolor
end
}bind def
后者应该只打印颜色空间的第一次使用。
注意:此代码未经测试,可能包含错误。