private BitmapSource GetBitmapSource(System.Windows.Size size, Boolean isCopyItem = false)
{
//FIXME: fix the cache retrieval options
//RetrievalOption = ShellThumbnailRetrievalOption.Default;
IntPtr hBitmap = GetHBitmap(size, isCopyItem);
// return a System.Media.Imaging.BitmapSource
// Use interop to create a BitmapSource from hBitmap.
if (hBitmap != IntPtr.Zero)
{
BitmapSource returnValue = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
System.Windows.Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions()).Clone();
// delete HBitmap to avoid memory leaks
Gdi32.DeleteObject(hBitmap);
return returnValue;
}
return null;
}