English 中文(简体)
如何比较两种系统。 引文。 Icon项目
原标题:How to compare two System.Drawing.Icon items

I am trying to fill a treeview in WPF with icons of files and folders, just like Windows Explorer does. The problem is, that it is very slow to load, because I am using a converter that just calls

return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, c.Width, c.Height), BitmapSizeOptions.FromEmptyOptions());

我认为,这为我收到的每份档案/文件创造了新的一席。 我用<代码>ManagedWinAPI的延伸检索图像。 因此,我现在正计划使用一种可相互比较的理论。

But how can I compare two System.Drawing.Icon objects? Because the reference is always different (tested). I don t need a pixel comparator, because I don t think that will speed up my process.

<>Update>

考虑到@Roy Dictus,该名词典仍然告诉我,名单上没有相同的物体:

Dictionary<byte[], ImageSource> data = new Dictionary<byte[], ImageSource>();

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    Icon c = (Icon)value;
    Bitmap bmp = c.ToBitmap();

    // hash the icon
    ImageConverter converter = new ImageConverter();
    byte[] rawIcon = converter.ConvertTo(bmp, typeof(byte[])) as byte[];

    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] hash = md5.ComputeHash(rawIcon);

    ImageSource result;

    data.TryGetValue(hash, out result);

    if (result == null)
    {
        PrintByteArray(hash); // custom method, prints the same values for two folder icons
        result = Imaging.CreateBitmapSourceFromHIcon(c.Handle, new Int32Rect(0, 0, c.Width, c.Height), BitmapSizeOptions.FromEmptyOptions());
        data.Add(hash, result);
    }
    else
    {
        Console.WriteLine("Found equal icons");
    }

    return result;
}
最佳回答

你们要么要比较比照图,要么根据比照图计算面值,然后比较这些数值。

这个关于视觉C# Kicks的员额显示,你如何从光标中计算出一个厚值。

EDIT: Some extra information based on how OP modified his question:

我肯定不会执行《公约》。 如果你能够将星座转换成一个能够执行可混合的护卫,那么它很可能会发挥作用。

你们可以把一阵列变成一个这样的阵列:

StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
    sb.Append(result[i].ToString("X2"));
}
问题回答

使用<代码>。 Handle as dictionary key.





相关问题
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. ...

热门标签