using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System. Web.ui.WebControls; use system.web.ui.htmlcontrols;
public class GetImage: System.Web.UI.Page {private void Page_Load (object sender, System.EventArgs e) {string strWidth = this.Request [ "width"]; string strHeight = this.Request [ "height"]; int width = -1, height = -1; try {width = Convert.ToInt32 (strWidth); height = Convert.ToInt32 (strHeight);} catch {} Response.ContentType = "image / JPEG"; FileStream fs = new FileStream ( @ "c: /file1.jpg", filemode.open, fileaccess.read; getzoomedlogo (fs, width, height, this.response.end ();}
Private void getzoomedlogo (System.io.Stream Originlogo, Int Width, Int Height, System.io.Stream OutputStream) {INT Drawidth = 0, DrawHeight = 0;
System.drawing.Image Origin = System.drawing.Image.Fromstream (OriginLogo);
IF (width == 0 && height == 0) // NOT Designate Width and Height {width = Origin.width; Height = Origin.Height;}
if (origin.Width ? Double scale = scaleX> scaleY scaleX: scaleY; drawWidth = Convert.ToInt32 (origin.Width / scale); drawHeight = Convert.ToInt32 (origin.Height / scale);} System.Drawing.Rectangle destRect = new Rectangle ((width - drawWidth) / 2, (height - drawHeight) / 2, drawWidth, drawHeight); Bitmap temp = new Bitmap (width, height); Graphics g = Graphics.FromImage (temp); SolidBrush brush = new SolidBrush (Color.White) G.FillRectangle (brush, 0, 0, width, height); // Draw background // g.drawline (New Pen (Color.Red, 10), 0, 0, 20, 20); if (width> = 300 || height> = 300) {g.DrawImage (origin, destRect);} else {System.Drawing.Image thumbnail = origin.GetThumbnailImage (drawWidth, drawHeight, null, System.IntPtr.Zero); g.drawImage (thumbnail, destRect); Temp.save (OutputStream, System.drawing.Imaging.imageFormat.jpeg); Origin.dispose (); temp.dispose (); g.dispose ();}}