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 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 ProcessRequest(HttpContext context)
        {
            var paramsStr = context.Request["params"];
            //判断图片是否存在
            var physicalPath = context.Request.PhysicalPath;

            if (string.IsNullOrEmpty(paramsStr))
            {
                context.Response.WriteFile(context.Request.PhysicalPath);
                return;
            }
            var thumbProperty = DefaultThumbnailNameProvider.GetThumbnailPropertyFromParamExpression(paramsStr);
            if (thumbProperty == null)
            {
                context.Response.WriteFile(context.Request.PhysicalPath);
                return;
            }
            var defaultThumbnailNameProvider = new DefaultThumbnailNameProvider();
            var originalFileInfo = new FileStoreInfo(physicalPath);
            var thumbImageFileInfo = defaultThumbnailNameProvider.GetThumbnailFileInfo(originalFileInfo, thumbProperty);
            if (!File.Exists(thumbImageFileInfo.FullFileName))
            {
                ImageUtility.Thumbnail(originalFileInfo, thumbProperty, defaultThumbnailNameProvider);
            }
            context.Response.ClearHeaders();
            context.Response.ContentType = "image/jpeg";
            context.Response.Headers.Add("Content-Type","image/jpeg");
            //context.Response.AddHeader("Content-Disposition", "attachment;filename=" + originalFileInfo.FileNameWithExtension);
            context.Response.WriteFile(thumbImageFileInfo.FullFileName);
        }
        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);
        }
Beispiel #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);
            }
        }
 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;
 }