Currently I'm getting a native icon by calling SHGetFileInfo. Then, I'm converting it to a bitmap using the following code. The Bitmap eventually gets displayed in the WPF form.
Is there a faster way to do the same thing?
try
{
using (Icon i = Icon.FromHandle(shinfo.hIcon))
{
Bitmap bmp = i.ToBitmap();
MemoryStream strm = new MemoryStream();
bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
strm.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = strm;
bmpImage.EndInit();
return bmpImage;
}
}
finally
{
Win32.DestroyIcon(hImgLarge);
}