Graphics in ASP

B

Barry

Hi

Can someone tell why i am not able to print the graphics text in the
following source (it is basically a copy of the ASPDraw sample from
Microsoft)

<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>

<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)
{

int width = 300;
int height = 200;
// Create a Bitmap instance
Bitmap objBitmap = new Bitmap(width, height);
Graphics objGraphics = Graphics.FromImage(objBitmap);

SolidBrush blackBrush = new SolidBrush(Color.Black);

// Put a white backround in
objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width,
height);

// we need to create fonts for our legend and title
Font fontLegend = new Font("Verdana", 10);
Font fontTitle = new Font("Verdana", 15, FontStyle.Bold);

int titleHeight = fontTitle.Height + 15;

// Create the title, centered
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;

objGraphics.DrawString("Is this Graphics", fontTitle, blackBrush,
new Rectangle(0, 0, width, titleHeight), stringFormat);

// clean up...
objGraphics.Dispose();

}

</script>

Barry
 
G

Guest

It’s easy:
1. Add an Image Control to your page.
2. Add the following code below objGraphics.Dispose();
objBitmap.Save("C:\\Inetpub\\wwwroot\\Site_Name\\Image.bmp",
ImageFormat.Bmp);
Image1.ImageUrl = "C:\\Inetpub\\wwwroot\\Site_Name\\Image.bmp";

Brad.
 
G

Guest

Also, if you get a GDI+ Error message with the code I just gave you. It's
probably your directory permissions (IIS needs write access).

Brad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top