示例#1
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;
                }
            }
        }