Simple Drawing : Graphics « Development « ASP.NET Tutorial






<%@ Page language="c#" Inherits="SimpleDrawing" CodeFile="Default.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <title>SimpleDrawing</title>
    </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
    </form>
  </body>
</HTML>
File: Default.aspx.cs

using System;
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;
using System.Web.UI.HtmlControls;

public partial class SimpleDrawing : System.Web.UI.Page
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
    Bitmap image = new Bitmap(300, 50);
    Graphics g = Graphics.FromImage(image);

    g.DrawRectangle(Pens.Green, 0, 0, 299, 49);

    Font font = new Font("Impact", 20, FontStyle.Regular);
    g.DrawString("This is a test.", font, Brushes.Blue, 10, 5);

        image.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

        g.Dispose();
        image.Dispose();
  }
}








9.22.Graphics
9.22.1.Simple Drawing
9.22.2.Mixed drawing
9.22.3.ThumbmailViewer