Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            using (var stream = new ReadonlyStream(this.Stream as IStream))
            {
                using (var memStream = new MemoryStream())
                {
                    stream.CopyTo(memStream);

                    memStream.Position = 0;

                    using (Bitmap thumbnail = GetThumbnail(memStream, cx))
                    {
                        if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
                        {
                            phbmp    = thumbnail.GetHbitmap(System.Drawing.Color.Transparent);
                            pdwAlpha = WTS_ALPHATYPE.WTSAT_ARGB;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            using var dataStream = new ReadonlyStream(this.Stream as IStream);
            using var memStream  = new MemoryStream();

            dataStream.CopyTo(memStream);
            memStream.Position = 0;

            // AsRandomAccessStream() extension method from System.Runtime.WindowsRuntime
            var pdf = PdfDocument.LoadFromStreamAsync(memStream.AsRandomAccessStream()).GetAwaiter().GetResult();

            if (pdf.PageCount > 0)
            {
                using var page = pdf.GetPage(0);

                var image = PageToImage(page, cx);

                using Bitmap thumbnail = new Bitmap(image);

                phbmp    = thumbnail.GetHbitmap();
                pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
            }
        }
Ejemplo n.º 3
0
        public int GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            try
            {
                Log.Info($"\nGetting thumbnail for {filePath}");

                using (Bitmap thumbnail = GetThumbnailsAsync(filePath, cx).GetAwaiter().GetResult())
                {
                    if (thumbnail == null)
                    {
                        return(WinError.E_FAIL);
                    }

                    phbmp    = thumbnail.GetHbitmap();
                    pdwAlpha = GetAlphaType(thumbnail);
                }

                return(WinError.S_OK);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(WinError.E_FAIL);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            string svgData = null;

            using (var stream = new StreamWrapper(this.Stream as IStream))
            {
                using (var reader = new StreamReader(stream))
                {
                    svgData = reader.ReadToEnd();
                }
            }

            if (svgData != null)
            {
                using (Bitmap thumbnail = GetThumbnail(svgData, cx))
                {
                    if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
                    {
                        phbmp    = thumbnail.GetHbitmap();
                        pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            Bitmap thumbnail = null;

            using (FileStream isoStream = File.OpenRead(this.FilePath))
            {
                UdfReader cd = new UdfReader(isoStream);
                //read META\DL img
                if (cd.Exists(@"BDMV\META\DL"))
                {
                    string[] files = cd.GetFiles(@"BDMV\META\DL", "*.jpg");
                    //find file that size is most similar and bigger than cx;
                    foreach (var item in files)
                    {
                        Stream fileStream = cd.OpenFile(item, FileMode.Open);
                        Bitmap bmp        = new Bitmap(fileStream);
                        if (thumbnail != null)
                        {
                            if ((cx < Math.Max(thumbnail.Width, thumbnail.Height) && Math.Max(bmp.Width, bmp.Height) < Math.Max(thumbnail.Width, thumbnail.Height)) ||
                                (cx > Math.Max(thumbnail.Width, thumbnail.Height) && Math.Max(bmp.Width, bmp.Height) > Math.Max(thumbnail.Width, thumbnail.Height)))
                            {
                                thumbnail = bmp;
                            }
                        }
                    }
                    if (thumbnail == null)
                    {
                        return;
                    }
                    if (thumbnail.Width != cx && thumbnail.Height != cx)
                    {
                        // We are not the appropriate size for caller.  Resize now while
                        // respecting the aspect ratio.
                        float scale       = Math.Min((float)cx / thumbnail.Width, (float)cx / thumbnail.Height);
                        int   scaleWidth  = (int)(thumbnail.Width * scale);
                        int   scaleHeight = (int)(thumbnail.Height * scale);
                        thumbnail = ResizeImage(thumbnail, scaleWidth, scaleHeight);
                    }
                    phbmp    = thumbnail.GetHbitmap();
                    pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
                }
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            string svgData = null;

            using (var stream = new ReadonlyStream(this.Stream as IStream))
            {
                using (var reader = new StreamReader(stream))
                {
                    svgData = reader.ReadToEnd();
                    try
                    {
                        // Fixes #17527 - Inkscape v1.1 swapped order of default and svg namespaces in svg file (default first, svg after).
                        // That resulted in parser being unable to parse it correctly and instead of svg, text was previewed.
                        // MS Edge and Firefox also couldn't preview svg files with mentioned order of namespaces definitions.
                        svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
                        svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (svgData != null)
            {
                using (Bitmap thumbnail = GetThumbnail(svgData, cx))
                {
                    if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
                    {
                        phbmp    = thumbnail.GetHbitmap();
                        pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void GetThumbnail(int cx, out IntPtr hBitmap, out WTS_ALPHATYPE bitmapType)
 {
     hBitmap = IntPtr.Zero;
     bitmapType = WTS_ALPHATYPE.WTSAT_UNKNOWN;
     FB2FileReader FB2File;
     try
     {
         //using (Bitmap Thumbnail = new Bitmap(cx, cx))
         //{
             FB2File = new FB2FileReader();
             byte[] vInput = GetStreamContents();
             MemoryStream stream = new MemoryStream(vInput);
             int size = FB2File.Read(vInput); //read your file
             if(size > 0)
             {
                 //create your thumbnail
                 //GCHandle vPinnedArray = GCHandle.Alloc(vBuffer, GCHandleType.Pinned);
                 //IntPtr vPointer = vPinnedArray.AddrOfPinnedObject();
                 //Bitmap new_bitmap = new Bitmap(188, 141, 564, System.Drawing.Imaging.PixelFormat.Format24bppRgb, vPointer);
                 byte[] vBuffer = FB2File.GetBuffer();
                 if (vBuffer != null && vBuffer.Length > 0)
                 {
                     Bitmap vBitmap = new Bitmap(new MemoryStream(vBuffer));
                     hBitmap = vBitmap.GetHbitmap();
                 }
                 else
                     hBitmap = IntPtr.Zero;
             }
         //}
     }
     catch
     {
         hBitmap = IntPtr.Zero;
     }
     finally
     {
         //I think this is the code that Ralfn was referencing, but this has NOT been tested
         _stream = null;
         FB2File = null;
         GC.Collect();
     }
 }
 public void GetThumbnail(int cx, out IntPtr hBitmap, out WTS_ALPHATYPE bitmapType)
 {
     hBitmap    = IntPtr.Zero;
     bitmapType = WTS_ALPHATYPE.WTSAT_ARGB;
     try
     {
         //... bunch of other code
         // set the hBitmap somehow
         using (MemoryStream stream = new MemoryStream(buffer))
             using (var image = new Bitmap(stream))
                 using (var scaled = new Bitmap(image, cx, cx))
                 {
                     hBitmap = scaled.GetHbitmap();
                 }
     }
     catch (Exception ex)
     {
     }
     // release the IStream COM object
     stream.Dispose();
 }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            if (cx == 0 || cx > MaxThumbnailSize)
            {
                return;
            }

            string svgData = null;

            using (var stream = new ReadonlyStream(this.Stream as IStream))
            {
                using (var reader = new StreamReader(stream))
                {
                    svgData = reader.ReadToEnd();
                    try
                    {
                        svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (svgData != null)
            {
                using (Bitmap thumbnail = GetThumbnail(svgData, cx))
                {
                    if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
                    {
                        phbmp    = thumbnail.GetHbitmap();
                        pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a thumbnail image and alpha type.
        /// </summary>
        /// <param name="cx">The maximum thumbnail size, in pixels. The Shell draws the returned bitmap at this size or smaller. The returned bitmap should fit into a square of width and height cx, though it does not need to be a square image. The Shell scales the bitmap to render at lower sizes. For example, if the image has a 6:4 aspect ratio, then the returned bitmap should also have a 6:4 aspect ratio.</param>
        /// <param name="phbmp">When this method returns, contains a pointer to the thumbnail image handle. The image must be a DIB section and 32 bits per pixel. The Shell scales down the bitmap if its width or height is larger than the size specified by cx. The Shell always respects the aspect ratio and never scales a bitmap larger than its original size.</param>
        /// <param name="pdwAlpha">When this method returns, contains a pointer to one of the following values from the WTS_ALPHATYPE enumeration.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        int IThumbnailProvider.GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            //  DebugLog this key event.
            Log(string.Format("GetThumbnail for item stream, width {0}.", cx));

            //  Set the out variables to default values.
            phbmp    = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;
            Bitmap thumbnailImage;

            try
            {
                //  Get the thumbnail image.
                thumbnailImage = GetThumbnailImage(cx);
            }
            catch (Exception exception)
            {
                //  DebugLog the exception and return failure.
                LogError("An exception occured when getting the thumbnail image.", exception);
                return(WinError.E_FAIL);
            }

            //  If we couldn't get an image, return failure.
            if (thumbnailImage == null)
            {
                //  DebugLog a warning return failure.
                Log("The internal GetThumbnail function failed to return a valid thumbnail.");
                return(WinError.E_FAIL);
            }

            //  Now we can set the image.
            phbmp    = thumbnailImage.GetHbitmap();
            pdwAlpha = WTS_ALPHATYPE.WTSAT_ARGB;

            //  Return success.
            return(WinError.S_OK);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets a thumbnail image and alpha type.
        /// </summary>
        /// <param name="cx">The maximum thumbnail size, in pixels. The Shell draws the returned bitmap at this size or smaller. The returned bitmap should fit into a square of width and height cx, though it does not need to be a square image. The Shell scales the bitmap to render at lower sizes. For example, if the image has a 6:4 aspect ratio, then the returned bitmap should also have a 6:4 aspect ratio.</param>
        /// <param name="phbmp">When this method returns, contains a pointer to the thumbnail image handle. The image must be a DIB section and 32 bits per pixel. The Shell scales down the bitmap if its width or height is larger than the size specified by cx. The Shell always respects the aspect ratio and never scales a bitmap larger than its original size.</param>
        /// <param name="pdwAlpha">When this method returns, contains a pointer to one of the following values from the WTS_ALPHATYPE enumeration.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        int IThumbnailProvider.GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
        {
            //  DebugLog this key event.
            Log(string.Format("GetThumbnail for item stream, width {0}.", cx));

            //  Set the out variables to default values.
            phbmp = IntPtr.Zero;
            pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;
            Bitmap thumbnailImage;

            try
            {
                //  Get the thumbnail image.
                thumbnailImage = GetThumbnailImage(cx);
            }
            catch(Exception exception)
            {
                //  DebugLog the exception and return failure.
                LogError("An exception occured when getting the thumbnail image.", exception);
                return WinError.E_FAIL;
            }

            //  If we couldn't get an image, return failure.
            if(thumbnailImage == null)
            {
                //  DebugLog a warning return failure.
                Log("The internal GetThumbnail function failed to return a valid thumbnail.");
                return WinError.E_FAIL;
            }

            //  Now we can set the image.
            phbmp = thumbnailImage.GetHbitmap();
            pdwAlpha = WTS_ALPHATYPE.WTSAT_ARGB;
          
            //  Return success.
            return WinError.S_OK;
        }
Ejemplo n.º 12
0
 public extern HRESULT GetThumbnail(uint cx, out HBITMAP phbmp, out WTS_ALPHATYPE pdwAlpha);
Ejemplo n.º 13
0
 public HRESULT GetThumbnail(uint cx, out SafeHBITMAP phbmp, out WTS_ALPHATYPE pdwAlpha)
 {
     // Retrieve thumbnails of the placeholders on demand by delegating to the thumbnail of the source items.
     try
     {
         using var thumbnailProviderSource = ComReleaserFactory.Create(_itemSrc.BindToHandler <IThumbnailProvider>(default, BHID.BHID_ThumbnailHandler.Guid()));
 public HRESULT InitializeBitmap(HBITMAP hbm, WTS_ALPHATYPE wtsAT)
 {
     return(((delegate * unmanaged <ISharedBitmap *, HBITMAP, WTS_ALPHATYPE, int>)(lpVtbl[6]))((ISharedBitmap *)Unsafe.AsPointer(ref this), hbm, wtsAT));
 }
Ejemplo n.º 15
0
        public void GetThumbnail(int squareLength, out IntPtr hBitmap, out WTS_ALPHATYPE bitmapType)
        {
            hBitmap = IntPtr.Zero;
            bitmapType = WTS_ALPHATYPE.WTSAT_UNKNOWN;

            #region cols
            Color[] pixel = new Color[16];

            pixel[0] = Color.FromArgb(255, 0, 0, 0);

            pixel[1] = Color.FromArgb(255, 0, 0, 192);
            pixel[2] = Color.FromArgb(255, 192, 0, 0);
            pixel[3] = Color.FromArgb(255, 192, 0, 192);
            pixel[4] = Color.FromArgb(255, 0, 192, 0);
            pixel[5] = Color.FromArgb(255, 0, 192, 192);
            pixel[6] = Color.FromArgb(255, 192, 192, 0);
            pixel[7] = Color.FromArgb(255, 192, 192, 192);

            pixel[8] = Color.FromArgb(255, 0, 0, 0);
            pixel[9] = Color.FromArgb(255, 0, 0, 255);
            pixel[10] = Color.FromArgb(255, 255, 0, 0);
            pixel[11] = Color.FromArgb(255, 255, 0, 255);
            pixel[12] = Color.FromArgb(255, 0, 255, 0);
            pixel[13] = Color.FromArgb(255, 0, 255, 255);
            pixel[14] = Color.FromArgb(255, 255, 255, 0);
            pixel[15] = Color.FromArgb(255, 255, 255, 255);
            #endregion

            try
            {
                //Do something with zx images..

                using (var Thumbnail = new Bitmap(256, 192)) //create surface and dispose
                {

                        #region init!?
                    byte[] scrn = new byte [6912];
                        byte[] s = new byte [6912];
                        scrn=this.GetStreamContents();
                    #endregion

                        #region initagain
                         #region diz

                        int addr = 0;

                         for (int l = 0; l <= 2; l++)
                         {
                            for (int j=0; j<=7; j++)
                            {
                                for (int x = (2048*l)+(j*32); x <= (2048 * (l + 1)) - 1; x += 256)
                                {
                                    for ( int z=0; z<=31;z++)
                                    {
                                        s[addr] = scrn [x+z];
                                        addr++;
                                    }
                                }
                            }
                         }

                        #endregion

                         #region ciz
                         addr = 0;
                         int lc = 0;
                         int ink = 0;
                         int paper =0;

                         for (int y = 0; y <= 191; y++)
                         {
                             for (int x = 0; x <= 31; x++)
                             {
                                 int bri = 0;
                                 int rng = scrn[6144 + ((int)(y / 8) * 32) + x];
                                 if ((rng & 128) != 0) {rng -=  128;}
                                 if ((rng & 64) != 0) { rng -= 64; bri = 8; }

                                 paper = ((int)(rng / 8));
                                 ink = (rng - (paper * 8)) + bri;
                                 paper += bri;

                                 lc = x * 8;

                                 switch (s[addr])
                                 {
                                    case 0:
                                         for (int i = 0; i <= 7; i++)
                                         {
                                             Thumbnail.SetPixel(lc + i, y, pixel[paper]);
                                         }
                                         break;
                                     case 255:
                                         for (int i = 0; i <= 7; i++)
                                         {
                                             Thumbnail.SetPixel(lc + i, y, pixel[ink]);
                                         }
                                         break;
                                     default:

                                          for ( byte z=0; z<=7 ; z++)
                                              {
                                                      byte r = (byte)Math.Pow(2, z);

                                                      if ((s[addr] & r) == r)
                                                      {
                                                          Thumbnail.SetPixel(lc + (7 - z), y, pixel[ink]);
                                                      }
                                                      else
                                                      {
                                                          Thumbnail.SetPixel(lc + (7 - z), y, pixel[paper]);
                                                      }

                                               }

                                         break;
                                 }
                                 addr++;
                             }

                         }

                         #endregion
            #endregion

                        #region draw
                         hBitmap = Thumbnail.GetHbitmap();
                         #endregion

                }

            }
            catch
            {
                //do nothing.
            }
        }