using System.Drawing;
using System.Drawing.Imaging;
//...
protected override void Render(HtmlTextWriter output)
{
Bitmap objBitmap = new Bitmap(120,30);
Graphics objGraphics = Graphics.FromImage(objBitmap); //Fill the background
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue),0,0,120,30);
//Create blue-yellow bullet point
objGraphics.FillEllipse(new SolidBrush(Color.Blue),3,9,10,10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow),4,10,8,8);
//Draw text next to bullet point
objGraphics.DrawString("Submit", new Font("Tahoma",8), new SolidBrush(Color.Green), 16,8);
//Render Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
objBitmap.Save(Page.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//Tidy up
objGraphics.Dispose();
objBitmap.Dispose();
}
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<title>Retrieving Image from the Sql Server</title>
<script runat=server>
Public Sub Page_Load(sender As Object, e As EventArgs)
' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("Select * from Person", myConnection)
Try
myConnection.Open()
Dim myDataReader as SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))
Loop
myConnection.Close()
Response.Write("Person info successfully retrieved!")
Catch SQLexc As SqlException
Response.Write("Read Failed : " & SQLexc.ToString())
End Try
End Sub
</script>
</HEAD>
<body style="font: 10pt verdana">
</body>
</HTML>