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 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);
     }
 }
Example #3
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);
            }
        }