Esempio n. 1
0
        /// <summary>
        /// Serializes the specified o.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <param name="sb">The sb.</param>
        public override void Serialize(object o, StringBuilder sb)
        {
            string id = Guid.NewGuid().ToString();

            AjaxBitmap b = new AjaxBitmap();

            b.bmp      = o as Bitmap;
            b.mimeType = this.mimeType;
            b.quality  = this.quality;

            System.Web.HttpContext.Current.Cache.Add(id, b,
                                                     null,
                                                     System.Web.Caching.Cache.NoAbsoluteExpiration,
                                                     TimeSpan.FromSeconds(30),
                                                     System.Web.Caching.CacheItemPriority.BelowNormal,
#if (NET20)
                                                     RemoveBitmapFromCache
#else
                                                     new System.Web.Caching.CacheItemRemovedCallback(RemoveBitmapFromCache)
#endif
                                                     );

            sb.Append("new ");
            sb.Append(clientType);
            sb.Append("('");
            sb.Append(id);
            sb.Append("')");
        }
Esempio n. 2
0
 /// <summary>
 /// Removes the bitmap from cache.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="o">The o.</param>
 /// <param name="reason">The reason.</param>
 public static void RemoveBitmapFromCache(string key, object o, System.Web.Caching.CacheItemRemovedReason reason)
 {
     if (o != null)
     {
         AjaxBitmap b = o as AjaxBitmap;
         if (b != null && b.bmp != null)
         {
             b.bmp.Dispose();
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            string id = System.IO.Path.GetFileNameWithoutExtension(context.Request.FilePath);

            AjaxBitmap b = null;

            try
            {
                Guid guid = new Guid(id);
                b = context.Cache[id] as AjaxBitmap;
            }
            catch (Exception) { }

            if (b == null || b.bmp == null)
            {
                b.bmp = new Bitmap(10, 20);
                Graphics g = Graphics.FromImage(b.bmp);
                g.FillRectangle(new SolidBrush(Color.White), 0, 0, 10, 20);
                g.DrawString("?", new Font("Arial", 10), new SolidBrush(Color.Red), 0, 0);
            }

            context.Response.ContentType = b.mimeType;

            if (b.mimeType.ToLower() == "image/jpeg")
            {
                ImageCodecInfo[] enc = ImageCodecInfo.GetImageEncoders();

                EncoderParameters ep = new EncoderParameters(1);
                ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, b.quality);

                b.bmp.Save(context.Response.OutputStream, enc[1], ep);
                return;
            }
            else
            {
                switch (b.mimeType.ToLower())
                {
                case "image/gif":
                    b.bmp.Save(context.Response.OutputStream, ImageFormat.Gif);
                    return;

                case "image/png":
                    b.bmp.Save(context.Response.OutputStream, ImageFormat.Png);
                    return;
                }
            }

            throw new NotSupportedException("'" + b.mimeType + "' is not supported.");
        }
        /// <summary>
        /// Serializes the specified o.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <param name="sb">The sb.</param>
		public override void Serialize(object o, StringBuilder sb)
		{
			string id = Guid.NewGuid().ToString();

			AjaxBitmap b = new AjaxBitmap();
			b.bmp = o as Bitmap;
			b.mimeType = this.mimeType;
			b.quality = this.quality;

			System.Web.HttpContext.Current.Cache.Add(id, b, 
				null, 
				System.Web.Caching.Cache.NoAbsoluteExpiration,
				TimeSpan.FromSeconds(30),
				System.Web.Caching.CacheItemPriority.BelowNormal,
#if(NET20)
				RemoveBitmapFromCache
#else
				new System.Web.Caching.CacheItemRemovedCallback(RemoveBitmapFromCache)
#endif
				);

			sb.Append("new ");
			sb.Append(clientType);
			sb.Append("('");
			sb.Append(id);
			sb.Append("')");
		}