2

我需要在我的 WEB 应用程序中检查图片是 sRGB 还是 Adob​​e RGB。有没有办法确切知道图片有什么RGB?

更新: 尝试使用 Color.Context,但它始终为空

代码

Bitmap img = (Bitmap)image;
var imgPixel = img.GetPixel(0,0);
System.Windows.Media.Color colorOfPixel= System.Windows.Media.Color.FromArgb(imgPixel.A,imgPixel.R, imgPixel.G, imgPixel.B);
var context = colorOfPixel.ColorContext; //ColorContext is null

在 System.Windows.Media 中还发现了 PixelFormat 和 PixelFormats 可以显示图像的确切 RGB 类型。但我仍然找不到获取 img 的 System.Windows.Media.PixelFormat 的方法。我该怎么做?

4

3 回答 3

3

您需要使用 aBitmapDecoder从那里获取框架,然后检查颜色上下文:

BitmapDecoder bitmapDec = BitmapDecoder.Create(
   new Uri("mybitmap.jpg", UriKind.Relative),
   BitmapCreateOptions.None,
   BitmapCacheOption.Default);
BitmapFrame bmpFrame = bitmapDec.Frames[0];
ColorContext context = bmpFrame.ColorContexts[0];

之后,您需要处理原始颜色配置文件(使用context.OpenProfileStream())以确定它是哪个配置文件。

如果您想将配置文件写入磁盘以使用十六进制编辑器或其他工具检查它们,您可以使用以下代码:

using(var fileStream = File.Create(@"myprofilename.icc"))
using (var st = context.OpenProfileStream())
{
  st.CopyTo(fileStream);
  fileStream.Flush(true);
  fileStream.Close();
}

使用该方法,如果您想检查它们,我已经从 sRGB(链接)和 Adob​​eRGB(链接)中提取了原始数据。如果您想检查,一开始有魔术字符串和 ID,但我真的不知道它们或知道在哪里可以找到常见的表(嵌入式配置文件可能是无限的,不限于 Adob​​eRGB 和 sRGB)。

此外,一张图像可能具有多个颜色配置文件。

使用此方法,如果ColorContexts为空,则图像没有任何配置文件。

于 2015-03-03T07:29:10.857 回答
1

Color.ColorContext 属性 MSDN:https ://msdn.microsoft.com/en-us/library/System.Windows.Media.Color_properties(v=vs.110).aspx

于 2015-02-26T04:28:29.200 回答
1

你可能会使用System.Drawing.Image.PropertyItems. 属性“PropertyTagICCProfile”(Id=34675=0x8773) 填充了图像的 icc 配置文件,即使它嵌入在图像数据中而不是 exif 数据中(或者没有嵌入配置文件,但图像被标记为 Adob​​eRGB在 exif 中:InteroperabilityIndex="R03")。

byte[] iccProfile = null;
try {
    System.Drawing.Bitmap myImage = new Bitmap("Image.jpg");
    iccProfile = myImage.GetPropertyItem(34675).Value;
} catch (Exception) {
    //...
}
于 2017-11-20T09:35:51.997 回答