Esempio n. 1
0
        /// <summary>
        ///     Takes care of resizeing image from url parameters
        /// </summary>
        /// <param name="parameters">
        ///     The parameters.
        /// </param>
        /// <param name="context">
        /// </param>
        /// <param name="imageFormat">
        /// </param>
        /// <returns>
        /// </returns>
        private byte[] GetImageData(IImageParameters parameters, HttpContext context, ImageFormat imageFormat)
        {
            IImageProvider provider = Factory.GetImageProvider();

            if (provider.IsNull())
            {
                throw new ApplicationException("Unable to determine image provider");
            }

            byte[] data = provider.GetImageData(parameters);
            if (data.IsNull())
            {
                return(null);
            }

            using (var sourceImageData = new MemoryStream(data))
            {
                var outputImg = (Bitmap)Image.FromStream(sourceImageData);
                foreach (IImageFilter imageFilter in this.m_ImageFilters)
                {
                    Bitmap oldOutputImage = outputImg;

                    bool modified = imageFilter.Process(parameters, context, ref outputImg);
                    if (modified)
                    {
                        // Dispose old bitmap
                        oldOutputImage.Dispose();
                    }
                }

                using (outputImg)
                {
                    // Encode image
                    return(s_ImageTool.Encode(outputImg, imageFormat));
                }
            }
        }