public static Bitmap ExtractImage(FileInfoEx entry, Size size, bool quality)
        {
            try
            {
                IntPtr        iExtractImagePtr = IntPtr.Zero;
                IExtractImage iExtractImage    = null;


                if (GetIExtractImage(entry, out iExtractImagePtr, out iExtractImage))
                {
                    try
                    {
                        ShellDll.ShellAPI.SIZE prgSize = new ShellAPI.SIZE()
                        {
                            cx = size.Width, cy = size.Height
                        };
                        IExtractImageFlags flags = IExtractImageFlags.Cache | IExtractImageFlags.Aspect;
                        if (quality)
                        {
                            flags |= IExtractImageFlags.Quality;
                        }
                        StringBuilder location = new StringBuilder(260, 260);

                        try
                        {
                            int pdwPriority = 1;
                            iExtractImage.GetLocation(location,
                                                      location.Capacity, ref pdwPriority, ref prgSize, 32, ref flags);
                        }
                        catch (COMException) { }

                        IntPtr ptrBitmapImage = IntPtr.Zero;
                        iExtractImage.Extract(out ptrBitmapImage);
                        if (ptrBitmapImage != IntPtr.Zero)
                        {
                            return(Bitmap.FromHbitmap(ptrBitmapImage));
                        }
                    }
                    catch (Exception) { }
                }
                finally
                {
                    if (iExtractImage != null)
                    {
                        Marshal.ReleaseComObject(iExtractImage);
                    }

                    if (iExtractImagePtr != IntPtr.Zero)
                    {
                        Marshal.Release(iExtractImagePtr);
                    }
                }

                return(null);
            }
예제 #2
0
        public static Bitmap ExtractImage(FileInfoEx entry, Size size, bool quality)
        {
            IntPtr        iExtractImagePtr = IntPtr.Zero;
            IExtractImage iExtractImage    = null;


            if (GetIExtractImage(entry, out iExtractImagePtr, out iExtractImage))
            {
                try
                {
                    ShellDll.ShellAPI.SIZE prgSize = new ShellAPI.SIZE()
                    {
                        cx = size.Width, cy = size.Height
                    };
                    IExtractImageFlags flags = IExtractImageFlags.Async | IExtractImageFlags.Aspect;
                    if (quality)
                    {
                        flags |= IExtractImageFlags.Quality;
                    }
                    StringBuilder location = new StringBuilder(260, 260);

                    try
                    {
                        iExtractImage.GetLocation(location,
                                                  location.Capacity, 1, prgSize, 32, flags);
                    }
                    catch (COMException) { }

                    IntPtr ptrBitmapImage = IntPtr.Zero;
                    iExtractImage.Extract(out ptrBitmapImage);
                    if (ptrBitmapImage != IntPtr.Zero)
                    {
                        return(Bitmap.FromHbitmap(ptrBitmapImage));
                    }
                }
                catch (Exception) { }
            }