Example #1
0
        private Bitmap GetBitmap(System.Windows.Size size)
        {
            IntPtr hBitmap = GetHBitmap(size);

            // return a System.Drawing.Bitmap from the hBitmap
            Bitmap returnValue = null;

            if (hBitmap != IntPtr.Zero)
            {
                returnValue = GetBitmapFromHBitmap(hBitmap);
            }

            // delete HBitmap to avoid memory leaks
            Gdi32.DeleteObject(hBitmap);

            return(returnValue);
        }
        private BitmapSource GetBitmapSource(System.Windows.Size size)
        {
            IntPtr hBitmap = GetHBitmap(size);

            // 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());

                // delete HBitmap to avoid memory leaks
                Gdi32.DeleteObject(hBitmap);
                return(returnValue);
            }

            return(null);
        }
Example #3
0
        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);
        }