Esempio n. 1
0
 public static void Thumbnail(FileStoreInfo originalImageFileInfo, ThumbnailProperty thumbnailProperty, IThumbnailNameProvider thumbnailWriteProvider = null, params ThumbnailProperty[] thumbnailProperties)
 {
     var defaultThumbnailWriteProvider = thumbnailWriteProvider;
     if (originalImageFileInfo == null)
         throw new ArgumentNullException("originalImageFileInfo");
     if (string.IsNullOrEmpty(originalImageFileInfo.FileNameWithExtension))
         throw new ArgumentException("originalImageFileInfo.FileNameWithExtension不能为空");
     if (thumbnailProperty == null)
         throw new ArgumentNullException("thumbnailProperty");
     if (!File.Exists(originalImageFileInfo.FullFileName))
         throw new FileNotFoundException(string.Format("路径:{0}的不存在", originalImageFileInfo.FullFileName));
     if (thumbnailWriteProvider == null)
         defaultThumbnailWriteProvider = new DefaultThumbnailNameProvider();
     var unionThumbnailPropertyies = new[] { thumbnailProperty };
     if (thumbnailProperties != null)
     {
         unionThumbnailPropertyies = unionThumbnailPropertyies.Union(thumbnailProperties).ToArray();
     }
     var originalImage = System.Drawing.Image.FromFile(originalImageFileInfo.FullFileName);
     foreach (var property in unionThumbnailPropertyies)
     {
         var fileInfo = defaultThumbnailWriteProvider.GetThumbnailFileInfo(originalImageFileInfo, thumbnailProperty);
         var thumbnailImage = CreateThumbnailImage(originalImage, property);
         thumbnailImage.Save(fileInfo.FullFileName);
     }
 }
 public void TestImageThumbnail()
 {
     var originalImageStoreFileInfoFirst = new FileStoreInfo("C:\\按周查看.bmp");
     var originalImageStoreFileInfoSecond = new FileStoreInfo()
     {
         FileNameWithoutExtension = "按周查看",
         FileDirectory = "c:\\",
         ExtensionName = ".bmp"
     };
     var thumbnailPropertyFisrt = new ThumbnailProperty()
     {
         Color = Color.White,
         Width = 200,
         Height = 200
     };
     var thumbnailPropertySecond = new ThumbnailProperty()
     {
         Color = Color.Transparent,
         Width = 940,
         Height = 360
     };
     var thumbnailPropertyThird = DefaultThumbnailNameProvider
         .GetThumbnailPropertyFromFileName("C:\\按周查看.bmp_thumb_800x400x0xoooooo.png");
     var ogrinalFileInfo =
         DefaultThumbnailNameProvider.GetOriginalFileNameFromFileName("C:\\按周查看.bmp_thumb_800x400x0xoooooo.png");
     ImageUtility.Thumbnail(originalImageStoreFileInfoFirst, thumbnailPropertyFisrt);
     ImageUtility.Thumbnail(originalImageStoreFileInfoSecond, thumbnailPropertySecond);
     ImageUtility.Thumbnail(originalImageStoreFileInfoSecond, thumbnailPropertyThird);
 }
        public FileStoreInfo GetThumbnailFileInfo(FileStoreInfo originalFileInfo, ThumbnailProperty thumbnailProperty)
        {
            Console.WriteLine(ColorHelper.ColorToHex(thumbnailProperty.Color));
            const string templateOfThumbName = "_thumb_{0}x{1}x{2}x{3}x{4}";
            //原文件名+"_thumb_[0width]x[1height]x[2zoomModeld]x[3fillModel]x[4color]"
            var postfix = string.Format(templateOfThumbName, thumbnailProperty.Width, thumbnailProperty.Height,
                                        (int)thumbnailProperty.ZoomModel, (int)thumbnailProperty.GraphFillModel, ColorHelper.ColorToHex(thumbnailProperty.Color));
            var fileStoreInfo = new FileStoreInfo()
            {
                ExtensionName = string.IsNullOrEmpty(thumbnailProperty.ExtensionName)
                    ? originalFileInfo.ExtensionName
                    : thumbnailProperty.ExtensionName,
                FileNameWithoutExtension = originalFileInfo.FileNameWithExtension + postfix,
                FileDirectory            = originalFileInfo.FileDirectory
            };

            return(fileStoreInfo);
        }
Esempio n. 4
0
 private static System.Drawing.Image CreateThumbnailImage(Image originalImage, ThumbnailProperty thumbnailProperty)
 {
     var width = originalImage.Width;
     var height = originalImage.Height;
     var targetWidth = thumbnailProperty.Width;
     var targetHeight = thumbnailProperty.Height;
     int newWidth, newHeight;
     Tuple<int, int> size;
     switch (thumbnailProperty.ZoomModel)
     {
         case ZoomModel.Ratio:
             size = CalculateWidthAndHeight(targetWidth, targetHeight, width, height, true);
             newWidth = size.Item1;
             newHeight = size.Item2;
             break;
         case ZoomModel.RatioOnlySmaller:
             size = CalculateWidthAndHeight(targetWidth, targetHeight, width, height, false);
             newWidth = size.Item1;
             newHeight = size.Item2;
             break;
         default:
             newWidth = thumbnailProperty.Width;
             newHeight = thumbnailProperty.Height;
             break;
     }
     newWidth = newWidth > targetWidth ? targetWidth : newWidth;
     newHeight = newHeight > targetHeight ? targetHeight : newHeight;
     if (thumbnailProperty.GraphFillModel == GraphFillModel.NonFill)
     {
         targetWidth = newWidth;
         targetHeight = newHeight;
     }
     var finalImage = new System.Drawing.Bitmap(targetWidth, targetHeight);
     var graphic = System.Drawing.Graphics.FromImage(finalImage);
     graphic.FillRectangle(new System.Drawing.SolidBrush(thumbnailProperty.Color), new System.Drawing.Rectangle(0, 0, targetWidth, targetHeight));
     var pasteX = (targetWidth - newWidth) / 2;
     var pasteY = (targetHeight - newHeight) / 2;
     graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
     graphic.DrawImage(originalImage, pasteX, pasteY, newWidth, newHeight);
     return finalImage;
 }
Esempio n. 5
0
        public static void Thumbnail(FileStoreInfo originalImageFileInfo, ThumbnailProperty thumbnailProperty, IThumbnailNameProvider thumbnailWriteProvider = null, params ThumbnailProperty[] thumbnailProperties)
        {
            var defaultThumbnailWriteProvider = thumbnailWriteProvider;

            if (originalImageFileInfo == null)
            {
                throw new ArgumentNullException("originalImageFileInfo");
            }
            if (string.IsNullOrEmpty(originalImageFileInfo.FileNameWithExtension))
            {
                throw new ArgumentException("originalImageFileInfo.FileNameWithExtension不能为空");
            }
            if (thumbnailProperty == null)
            {
                throw new ArgumentNullException("thumbnailProperty");
            }
            if (!File.Exists(originalImageFileInfo.FullFileName))
            {
                throw new FileNotFoundException(string.Format("路径:{0}的不存在", originalImageFileInfo.FullFileName));
            }
            if (thumbnailWriteProvider == null)
            {
                defaultThumbnailWriteProvider = new DefaultThumbnailNameProvider();
            }
            var unionThumbnailPropertyies = new[] { thumbnailProperty };

            if (thumbnailProperties != null)
            {
                unionThumbnailPropertyies = unionThumbnailPropertyies.Union(thumbnailProperties).ToArray();
            }
            var originalImage = System.Drawing.Image.FromFile(originalImageFileInfo.FullFileName);

            foreach (var property in unionThumbnailPropertyies)
            {
                var fileInfo       = defaultThumbnailWriteProvider.GetThumbnailFileInfo(originalImageFileInfo, thumbnailProperty);
                var thumbnailImage = CreateThumbnailImage(originalImage, property);
                thumbnailImage.Save(fileInfo.FullFileName);
            }
        }
Esempio n. 6
0
 public static void Thumbnail(Stream stream, string thumbnailPath, ThumbnailProperty thumbnailProperty, params ThumbnailProperty[] thumbnailProperties)
 {
 }
 public FileStoreInfo GetThumbnailFileInfo(FileStoreInfo originalFileInfo, ThumbnailProperty thumbnailProperty)
 {
     Console.WriteLine(ColorHelper.ColorToHex(thumbnailProperty.Color));
     const string templateOfThumbName = "_thumb_{0}x{1}x{2}x{3}x{4}";
     //原文件名+"_thumb_[0width]x[1height]x[2zoomModeld]x[3fillModel]x[4color]"
     var postfix = string.Format(templateOfThumbName, thumbnailProperty.Width, thumbnailProperty.Height,
             (int)thumbnailProperty.ZoomModel, (int)thumbnailProperty.GraphFillModel, ColorHelper.ColorToHex(thumbnailProperty.Color));
     var fileStoreInfo = new FileStoreInfo()
     {
         ExtensionName = string.IsNullOrEmpty(thumbnailProperty.ExtensionName)
             ? originalFileInfo.ExtensionName
             : thumbnailProperty.ExtensionName,
         FileNameWithoutExtension = originalFileInfo.FileNameWithExtension + postfix,
         FileDirectory = originalFileInfo.FileDirectory
     };
     return fileStoreInfo;
 }
Esempio n. 8
0
        private static System.Drawing.Image CreateThumbnailImage(Image originalImage, ThumbnailProperty thumbnailProperty)
        {
            var width = originalImage.Width;
            var height = originalImage.Height;
            var targetWidth = thumbnailProperty.Width;
            var targetHeight = thumbnailProperty.Height;
            int newWidth, newHeight;
            Tuple <int, int> size;

            switch (thumbnailProperty.ZoomModel)
            {
            case ZoomModel.Ratio:
                size      = CalculateWidthAndHeight(targetWidth, targetHeight, width, height, true);
                newWidth  = size.Item1;
                newHeight = size.Item2;
                break;

            case ZoomModel.RatioOnlySmaller:
                size      = CalculateWidthAndHeight(targetWidth, targetHeight, width, height, false);
                newWidth  = size.Item1;
                newHeight = size.Item2;
                break;

            default:
                newWidth  = thumbnailProperty.Width;
                newHeight = thumbnailProperty.Height;
                break;
            }
            newWidth  = newWidth > targetWidth ? targetWidth : newWidth;
            newHeight = newHeight > targetHeight ? targetHeight : newHeight;
            if (thumbnailProperty.GraphFillModel == GraphFillModel.NonFill)
            {
                targetWidth  = newWidth;
                targetHeight = newHeight;
            }
            var finalImage = new System.Drawing.Bitmap(targetWidth, targetHeight);
            var graphic    = System.Drawing.Graphics.FromImage(finalImage);

            graphic.FillRectangle(new System.Drawing.SolidBrush(thumbnailProperty.Color), new System.Drawing.Rectangle(0, 0, targetWidth, targetHeight));
            var pasteX = (targetWidth - newWidth) / 2;
            var pasteY = (targetHeight - newHeight) / 2;

            graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            graphic.DrawImage(originalImage, pasteX, pasteY, newWidth, newHeight);
            return(finalImage);
        }
Esempio n. 9
0
 public static void Thumbnail(Stream stream, string thumbnailPath, ThumbnailProperty thumbnailProperty, params ThumbnailProperty[] thumbnailProperties)
 {
 }