English 中文(简体)
C# 比较
原标题:C# compare pixelformats

How can i compare pixel formats of 2 images?

i) 尝试:

if (img1.PixelFormat > img2.PixelFormat)

但“Format8bppIndexed”被评为大于“Format24bppRgb”

什么是错了?

问题回答

比较是有效的,但你只是比较点数的/strong>,因此,结果将取决于数值的界定顺序。

如果你需要比较图像格式,那么你就必须制定规则。 什么价值是“比”另一数值取决于您的申请。

http://stackoverflow.com/users/1583/oded>@Od 在其评论中,你可以形成一个<代码>Dictionary,该编码与PixelFormat相挂钩,使您的比较具有正确的相对价值(颜色深度),以换取你的检测结果和使用。

如果你想按自己的深度比较图像,尝试如下,对我来说就是这样:

/// <summary>
/// Returns the bit depth of <paramref name="image"/>.
/// </summary>
public static int GetBitDepth(this Image image)
{
    return ((int) image.PixelFormat >> 8) & 0xFF;
}

这是一个老问题,但鉴于似乎没有人实际将显而易见的答案贴在了<条码>。 因此,<代码>Format16bppArgb1555将返回16/code>。

Int32 pixSize1 = Image.GetPixelFormatSize(img1.PixelFormat);
Int32 pixSize2 = Image.GetPixelFormatSize(img2.PixelFormat);
if (pixSize1 > pixSize2)
{
    ...
}

虽然我真的想知道,为什么你会检查,除非是区分指数格式,否则,如果转换为较低的购买力平价,那么你就不可能写上更高的字面指数。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...