Windowsエクスプローラーのように、WPFのツリービューにファイルとフォルダのアイコンを入力しようとしています。問題は、私はちょうど私は、これは私が得るすべてのファイル/フォルダの新しいアイコンを作成することを前提としてい2つのSystem.Drawing.Iconアイテムを比較する方法
return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, c.Width, c.Height), BitmapSizeOptions.FromEmptyOptions());
を呼び出すコンバータを使用していますので、ロードすることは非常に遅いこと、です。私はManagedWinAPI
拡張子の画像を取得します。だから今、私はアイコンを互いに比較できる辞書を使うつもりだった。
しかし、2つのSystem.Drawing.Icon
オブジェクトを比較するにはどうすればよいですか?参照は常に異なる(テスト済み)ためです。ピクセルコンパレータは必要ありません。なぜなら、プロセスをスピードアップするとは思わないからです。
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;
}
どのアイコンを読み込むかはどのように分かりますか? –
'CreateBitmapSourceFromHIcon'を使うよりもアイコンにアクセスして変換する方が効率的です。これは、アンマネージドアイコンデータを扱うためのものです。 –
@Damien私はこれを見つけられませんでしたが、これはWFP ImageSourceに持っていくようです。 – Marnix