Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net streaming image hangs

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Hi. I've written a script to create a chart image using the Bitmap and Graphics object. The image is created at each time the webpage is requested and is streamed direct to the web page. The chart is drawn based on data which it recieves via a querystring. The problem is that it works for a while, but if I return to it after lunch for example the whole script just hangs as if it is in a continuous loop. It doesn't display any errors, it just doesn't load. The data hasn't changed since the last time it worked. This is my first asp.net script so maybe I've overlooked something obvious. I've pasted the script below. Many thanks in advance. Modalman



<%@ Page Language=&quot;VB&quot; Debug=&quot;True&quot; %>
<%@ Import Namespace=&quot;System.Drawing&quot; %>
<%@ Import Namespace=&quot;System.Drawing.Imaging&quot; %>
<%@ Import Namespace=&quot;System.Drawing.Text&quot; %>
<%
' Declare Vars
Dim objBMP As System.Drawing.Bitmap
Dim objGraphics As System.Drawing.Graphics
Dim objFont As System.Drawing.Font
Dim objPenGray As System.Drawing.Pen
Dim objPenRed As System.Drawing.Pen
Dim objPenBlack As System.Drawing.Pen

Dim picH As Integer
Dim picW As Integer
Dim weightHis As String
Dim verScaleFrom As Integer
Dim verScaleSep As Integer
Dim verScaleCalib As Double
Dim horScaleSep As Integer
Dim tgtWeight As Double
Dim perWeight As Double
Dim verCalPix As Integer
Dim horCalPix As Integer
Dim verH As Integer
Dim i As Integer
Dim weightAr As Array
Dim prevX As Integer
Dim prevY As Integer
Dim newX As Integer
Dim newY As Integer
Dim tgtY As Integer
Dim tgtBound As Integer











picH=Request(&quot;h&quot;)
picW=Request(&quot;w&quot;)
weightHis=Request(&quot;weightHis&quot;)
'picH=280
'picW=600
'weightHis=&quot;84,83,80.5,81,79,77.5,75,72,72,71&quot;
verScaleFrom=Request(&quot;verScaleFrom&quot;)
'verScaleFrom=80
verScaleSep=Request(&quot;verScaleSep&quot;)
verScaleCalib=Request(&quot;verScaleCalib&quot;) 'kgs or lbs
horScaleSep=Request(&quot;horScaleSep&quot;)
weightAr=Split(weightHis,&quot;,&quot;)
tgtWeight=Request(&quot;tgtWeight&quot;)






objBMP = New Bitmap(picW, picH)
' Create a graphics object to work with from the BMP
objGraphics = System.Drawing.Graphics.FromImage(objBMP)

objPenBlack=new Pen(Color.Black, 2)
objPenRed=new Pen(Color.Red, 1)
objPenGray=new Pen(Color.FromArgb(200,200,200), 1)

' Configure font to use for text
objFont = New Font(&quot;Arial&quot;, 8, FontStyle.Regular)







' Fill the image with background color
'objGraphics.Clear(Color.Green)
objGraphics.FillRectangle(new SolidBrush(Color.White),0,0,picW,picH)

For i=picH-1 To 0 Step -verScaleSep
objGraphics.DrawLine(objPenGray,0,i,picW-1,i)
Next

For i=0 To picW Step horScaleSep
objGraphics.DrawLine(objPenGray,i,0,i,picH-1)
Next





'plot to chart
If UBound(weightAr)>0 Then
prevX=0
prevY=CInt(picH-((((weightAr(0)*1)-verScaleFrom)/verScaleCalib)*verScaleSep))
objGraphics.DrawString(weightAr(0)&&quot; kg&quot;, objFont, Brushes.Black,prevX,prevY-20)
objGraphics.FillRectangle(Brushes.Black, prevX-2, prevY-2, 4, 4)

For i=1 To UBound(weightAr)
newX=prevX+horScaleSep
newY=CInt(picH-((((weightAr(i)*1)-verScaleFrom)/verScaleCalib)*verScaleSep))
objGraphics.DrawLine(objPenBlack,prevX,prevY,newX,newY)
objGraphics.FillRectangle(Brushes.Black, newX-2, newY-2, 4, 4)

objGraphics.DrawString(weightAr(i)&&quot; kg&quot;, objFont, Brushes.Black,newX,newY-20)

prevX=newX
prevY=newY
Next
End If






'draw tgt lines based on perWeight
newY=CInt(picH-((((weightAr(0)*1)-verScaleFrom)/verScaleCalib)*verScaleSep))
tgtY=CInt(picH-((((tgtWeight*1)-verScaleFrom)/verScaleCalib)*verScaleSep))
objGraphics.DrawLine(objPenRed,0,newY,13*horScaleSep,tgtY)

tgtBound=(((weightAr(0)*.05)/verScaleCalib)*verScaleSep)
objGraphics.DrawLine(objPenRed,0,newY-tgtBound,13*horScaleSep,tgtY-tgtBound)

objGraphics.DrawLine(objPenRed,0,newY+tgtBound,13*horScaleSep,tgtY+tgtBound)




' Set the content type and return the image
Response.ContentType = &quot;image/GIF&quot;
objBMP.Save(Response.OutputStream, ImageFormat.Gif)

' Kill our objects
objFont.Dispose()
objGraphics.Dispose()
objBMP.Dispose()
objPenGray.Dispose()
objPenBlack.Dispose()
objPenRed.Dispose()
%>

ASCII silly question, get a silly ANSI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top