Ejemplo n.º 1
0
        protected override Bitmap GetThumbnailImage(uint width)
        {
            using (var thumb = loader.GetThumbnail(SelectedItemStream))
            {
                int newWidth, newHeight;
                if (thumb.Width > thumb.Height)
                {
                    if (width > thumb.Width)
                    {
                        newWidth  = thumb.Width;
                        newHeight = thumb.Height;
                    }
                    else
                    {
                        newWidth  = (int)width;
                        newHeight = (int)(thumb.Height * (float)width / thumb.Width);
                    }
                }
                else
                {
                    if (width > thumb.Height)
                    {
                        newWidth  = thumb.Width;
                        newHeight = thumb.Height;
                    }
                    else
                    {
                        newWidth  = (int)(thumb.Width * (float)width / thumb.Height);
                        newHeight = (int)width;
                    }
                }

                var result = new Bitmap(newWidth, newHeight);
                using (var g = Graphics.FromImage(result))
                {
                    g.DrawImage(thumb, 0, 0, result.Width, result.Height);
                }

                return(result);
            }
        }