예제 #1
0
        protected static Image GenerateThumbnail(Image img, Thumbnails.Size maxPxSize)
        {
            Size thumbnailSize = GetThumbnailSize(img, Thumbnails.Size.Px32);

            return(img.GetThumbnailImage(thumbnailSize.Width,
                                         thumbnailSize.Height, null, IntPtr.Zero));
        }
예제 #2
0
        public byte[] GetIcon(string type, Thumbnails.Size size)
        {
            var icon = IconsData[size].GetObject(type) as byte[];

            if (icon == null)
            {
                return(IconsData[size].GetObject(BLANK) as byte[]);
            }

            return(icon);
        }
 public byte[] GetThumbnailForExtension(string extension, Thumbnails.Size pxSize = Thumbnails.Size.Px32)
 {
     try
     {
         return(iconsStorage.GetIcon(extension, pxSize));
     }
     catch (Exception)
     {
         return(iconsStorage.GetIcon("_blank", pxSize));
     }
 }
        public byte[] GetThumbnailForMimeType(string mimeType, Thumbnails.Size pxSize = Thumbnails.Size.Px32)
        {
            try
            {
                var extension = MimeTypeMap.GetExtension(mimeType).Replace(".", "");

                return(iconsStorage.GetIcon(extension, pxSize));
            }
            catch (Exception)
            {
                return(iconsStorage.GetIcon("_blank", pxSize));
            }
        }
예제 #5
0
        protected static Size GetThumbnailSize(Image original, Thumbnails.Size maxPxSize)
        {
            double factor;

            if (original.Width > original.Height)
            {
                factor = (double)maxPxSize / original.Width;
            }
            else
            {
                factor = (double)maxPxSize / original.Height;
            }

            return(new Size((int)(original.Width * factor), (int)(original.Height * factor)));
        }
        public void GetThumbnailForImageReturnsProperIcon_Px(Thumbnails.Size size)
        {
            var target = new IconThumbnail();

            // Act
            var blankIcon = target.GetThumbnailForMimeType("blank", size);
            var pngIcon   = target.GetThumbnailForMimeType("image/png", size);
            var jpegIcon  = target.GetThumbnailForMimeType("image/jpeg", size);
            var bmpIcon   = target.GetThumbnailForMimeType("image/bmp", size);
            var tiffIcon  = target.GetThumbnailForMimeType("image/tiff", size);
            var gifIcon   = target.GetThumbnailForMimeType("image/gif", size);
            var xlsxIcon  = target.GetThumbnailForMimeType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", size);
            var xlsmIcon  = target.GetThumbnailForMimeType("application/vnd.ms-excel.sheet.macroEnabled.12", size);

            // Assert
            CheckImageIcon(blankIcon, (int)size);
            CheckImageIcon(pngIcon, (int)size);
            CheckImageIcon(jpegIcon, (int)size);
            CheckImageIcon(bmpIcon, (int)size);
            CheckImageIcon(tiffIcon, (int)size);
            CheckImageIcon(gifIcon, (int)size);
            CheckImageIcon(xlsxIcon, (int)size);
            CheckImageIcon(xlsmIcon, (int)size);
        }
예제 #7
0
 public ImageThumbnail(Stream image, Thumbnails.Size thumbnailMaxPxSize = Thumbnails.Size.Px32)
 {
     ImgThumbnail = GenerateThumbnail(Image.FromStream(image), thumbnailMaxPxSize);
 }