Beispiel #1
0
        private bool TryProcessRequestFromCache(HttpResponse response)
        {
            bool retVal = false;

            byte[] imageBytes = ImageCacheBroker.GetImageBytes();
            if (imageBytes != null && imageBytes.Length > 0)
            {
                response.ContentType = ImageMetadata.ContentType;
                response.AppendHeader("Content-Disposition", string.Concat("inline; filename=\"", ImageMetadata.SaveName, "\""));
                response.AppendHeader("Content-Length", imageBytes.Length.ToString(CultureInfo.InvariantCulture));
                response.Cache.SetCacheability(HttpCacheability.Public);
                response.Cache.SetAllowResponseInBrowserHistory(true);
                response.Cache.SetLastModified(ImageMetadata.LastModifiedDate);
                response.Cache.SetValidUntilExpires(true);
                response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(ImageSettings.ClientCacheTimeout));

                response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
                retVal = true;
            }

            return(retVal);
        }
Beispiel #2
0
        private void ProcessFullRequest(HttpResponse response)
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                ImageTransformer imageTransformer = new ImageTransformer();
                imageTransformer.GraphicsQuality = ImageSettings.GraphicsQuality;
                imageTransformer.Copyright       = ImageSettings.Copyright;
                imageTransformer.CopyrightSize   = ImageSettings.CopyrightSize;
                imageTransformer.MaxWidth        = ImageSettings.MaxWidth;
                imageTransformer.MaxHeight       = ImageSettings.MaxHeight;
                imageTransformer.Grayscale       = ImageSettings.Grayscale;
                imageTransformer.Negative        = ImageSettings.Negative;
                imageTransformer.Sepia           = ImageSettings.Sepia;
                imageTransformer.Clip            = ImageSettings.Clip;
                imageTransformer.Quantize        = ImageSettings.Quantize;
                imageTransformer.MaintainPalette = ImageSettings.MaintainPalette;
                imageTransformer.Brightness      = ImageSettings.Brightness;
                imageTransformer.Contrast        = ImageSettings.Contrast;
                imageTransformer.Opacity         = ImageSettings.Opacity;

                string customTransform = ImageSettings.CustomTransform;
                if (!string.IsNullOrEmpty(customTransform))
                {
                    string         customTransformClassName = config.GetImageTransformClassName(customTransform);
                    ImageTransform customTransformClass     = ImageTransformFactory.Create(customTransformClassName);

                    ICustomDataConsumer customTransFormClassAsCustomDataConsumer = customTransformClass as ICustomDataConsumer;
                    if (customTransFormClassAsCustomDataConsumer != null)
                    {
                        customTransFormClassAsCustomDataConsumer.SetCustomData(ImageSettings.CustomData);
                    }

                    imageTransformer.CustomTransforms.Add(customTransformClass);
                }

                ImageRetriever.EnsureImage();
                using (Image originalImage = ImageRetriever.GetImage())
                    using (Image resizedBitmap = imageTransformer.Transform(originalImage)) {
                        long        outputQuality = ImageSettings.OutputQuality;
                        ImageFormat imageFormat   = ImageMetadata.ImageFormat;

                        resizedBitmap.SaveToMemoryStream(memoryStream, imageFormat, outputQuality);
                    }

                memoryStream.Capacity = (int)memoryStream.Position;



                if (memoryStream.Capacity > 0)
                {
                    if (ImageSettings.ServerCacheTimeout > 0)
                    {
                        ImageCacheBroker.AddImageBytes(memoryStream.ToArray());
                    }

                    response.ContentType = ImageMetadata.ContentType;
                    response.AppendHeader("Content-Disposition", string.Concat("inline; filename=\"", ImageMetadata.SaveName, "\""));
                    response.AppendHeader("Content-Length", memoryStream.Capacity.ToString(CultureInfo.InvariantCulture));
                    response.Cache.SetCacheability(HttpCacheability.Public);
                    response.Cache.SetAllowResponseInBrowserHistory(true);
                    response.Cache.SetLastModified(ImageMetadata.LastModifiedDate);
                    response.Cache.SetValidUntilExpires(true);
                    response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(ImageSettings.ClientCacheTimeout));

                    memoryStream.WriteTo(response.OutputStream);
                }
            }
        }