ASP.NET Tutorial/Page Lifecycle/Mime type
Gif image
<source lang="csharp">
<%@ Page language="c#" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.Drawing.Drawing2D" %> <%@ Import Namespace="System.Drawing.Text" %> <script runat="server">
private void Page_Load(object sender, System.EventArgs e) { Bitmap InputBitmap = new Bitmap(Server.MapPath("logo.gif")); int newWidth = 100; int newHeight = 100; Bitmap OutputBitmap = new Bitmap(InputBitmap, newWidth, newHeight); Response.Clear(); Response.ContentType="image/Gif"; OutputBitmap.Save(Response.OutputStream, ImageFormat.Gif); OutputBitmap.Dispose(); InputBitmap.Dispose(); }
</script></source>
JPeg image
<source lang="csharp">
<%@ Page language="c#" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.Drawing.Drawing2D" %> <%@ Import Namespace="System.Drawing.Text" %> <script runat="server">
private void Page_Load(object sender, System.EventArgs e) { Bitmap OutputBitmap = new Bitmap(Server.MapPath("1.jpg")); Graphics DrawGraphic = Graphics.FromImage(OutputBitmap); DrawGraphic.SmoothingMode = SmoothingMode.AntiAlias; DrawGraphic.TextRenderingHint = TextRenderingHint.AntiAlias; String MessageString = System.DateTime.Now.ToString(); DrawGraphic.DrawString(MessageString, new Font("arial",8,FontStyle.Bold), Brushes.DarkBlue, new PointF(10,22)); Response.Clear(); Response.ContentType="image/jpeg"; OutputBitmap.Save(Response.OutputStream, ImageFormat.Jpeg); OutputBitmap.Dispose(); DrawGraphic.Dispose(); }
</script></source>
set the mime type
<source lang="csharp">
<%@ Page language="c#" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.Drawing.Drawing2D" %> <%@ Import Namespace="System.Drawing.Text" %> <script runat="server">
private void Page_Load(object sender, System.EventArgs e) { Bitmap OutputBitmap = new Bitmap(320,200); Graphics DrawGraphic = Graphics.FromImage(OutputBitmap); DrawGraphic.Clear(Color.Beige); DrawGraphic.SmoothingMode = SmoothingMode.AntiAlias; DrawGraphic.TextRenderingHint = TextRenderingHint.AntiAlias; String MessageString = System.DateTime.Now.ToString(); DrawGraphic.DrawString(MessageString, new Font("arial",18,FontStyle.Bold), Brushes.DarkBlue, new PointF(20,20)); Response.Clear(); Response.ContentType="image/jpeg"; OutputBitmap.Save(Response.OutputStream, ImageFormat.Jpeg); OutputBitmap.Dispose(); DrawGraphic.Dispose(); }
</script></source>