473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem creating images on the fly

I'm developing a website and for one of the pages I need to create a number
of coloured rectangles - its part of a legend and the user has control over
the actual colours used which is why I want to create it dynamically. I've
put together an aspx.vb page which creates a rectangle as a jpeg in the
colour passed via the url. My idea being to pull in each coloured rectangle
using something like:

<img
src="rectangle.aspx?width=30&height=20&colour=FF00 00&border=C0C0C0">

This SEEMS to work, BUT the first time I view the page all but one of my
images fails to load. (Explorer displays the symbol for a missing image.) If
I refresh the page (or visit it again a few minutes later) then its fine.
Any ideas what I could be doing wrong?

If its relevant, my code for generating the image is:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here.
' Extract the definition of the image we require.
Dim width As Integer =
Val(HttpContext.Current.Request.Params("width"))
If width = 0 Then
width = 20
End If
Dim height As Integer =
Val(HttpContext.Current.Request.Params("height"))
If height = 0 Then
height = 20
End If
Dim colour As String = HttpContext.Current.Request.Params("colour")
Dim border As String = HttpContext.Current.Request.Params("border")
' Draw rectangle.
Dim bitmap As New Bitmap(width, height)
Dim graph As Graphics = Graphics.FromImage(bitmap)
Dim fillBrush As New SolidBrush(HTMLtoRGB(colour))
If border = "" Then
graph.FillRectangle(fillBrush, 0, 0, width, height)
Else
Dim outlinePen As New Pen(HTMLtoRGB(border), 1)
graph.DrawRectangle(outlinePen, 0, 0, width, height)
graph.FillRectangle(fillBrush, 1, 1, width - 2, height - 2)
outlinePen.Dispose()
End If
fillBrush.Dispose()
' Send this to the output.
Dim memStream As New MemoryStream
Response.Clear()
Response.ContentType = "image/jpeg"
bitmap.Save(memStream, ImageFormat.Jpeg)
memStream.WriteTo(Response.OutputStream)
' Tidy up.
bitmap.Dispose()
End Sub

thanks in advance,

Brian Cryer

www.cryer.co.uk/brian
Nov 21 '05 #1
5 1219
"Brian Cryer" <br****@127.0.0.1.activesol.co.uk> schrieb:
<img
src="rectangle.aspx?width=30&height=20&colour=FF00 00&border=C0C0C0">


This won't solve your problem, but don't forget to encode the ampersands:

\\\
<img
src="rectangle.aspx?width=30&amp;height=20&amp;col our=FF0000&amp;border=C0C0C0"/>
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

"Brian Cryer" <br****@127.0.0.1.activesol.co.uk> wrote
I'm developing a website and for one of the pages I need to create a number
of coloured rectangles - its part of a legend and the user has control over
the actual colours used which is why I want to create it dynamically. I've
put together an aspx.vb page which creates a rectangle as a jpeg in the
colour passed via the url. My idea being to pull in each coloured rectangle
using something like:

<img
src="rectangle.aspx?width=30&height=20&colour=FF00 00&border=C0C0C0">


Was there some reason you did not try using HTML objects to build your
colored rectangles? Something like the DIV object seems like it would suit
your needs, without having to build bitmaps....

LFS

Nov 21 '05 #3
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
"Brian Cryer" <br****@127.0.0.1.activesol.co.uk> schrieb:
<img
src="rectangle.aspx?width=30&height=20&colour=FF00 00&border=C0C0C0">
This won't solve your problem, but don't forget to encode the ampersands:

\\\
<img

src="rectangle.aspx?width=30&amp;height=20&amp;col our=FF0000&amp;border=C0C0
C0"/> ///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Herfried,

Ouch (kicks himself) very good point, (but you're right ... it doesn't solve
my problem).

Thanks,

Brian.

www.cryer.co.uk/brian
Nov 21 '05 #4
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...

"Brian Cryer" <br****@127.0.0.1.activesol.co.uk> wrote
I'm developing a website and for one of the pages I need to create a number of coloured rectangles - its part of a legend and the user has control over the actual colours used which is why I want to create it dynamically. I've put together an aspx.vb page which creates a rectangle as a jpeg in the
colour passed via the url. My idea being to pull in each coloured rectangle using something like:

<img
src="rectangle.aspx?width=30&height=20&colour=FF00 00&border=C0C0C0">
Was there some reason you did not try using HTML objects to build your
colored rectangles? Something like the DIV object seems like it would

suit your needs, without having to build bitmaps....

LFS
Good point. I started out using a table and setting the background colour.
That worked fine until some people printed it and the colours didn't come
out. I realise this is down to their configuration Tools > Internet Options Advanced > Printing with "Print background colors and images" unchecked,

but telling the users to change their settings isn't an ideal solution.

I assume that if I were to use DIVs then I would hit the same problem?
Please correct me if I'm wrong.

thanks,

Brian.

Nov 21 '05 #5

"Brian Cryer" <br****@127.0.0.1.activesol.co.uk> wrote
Was there some reason you did not try using HTML objects to build your
colored rectangles? Something like the DIV object seems like it would suit
your needs, without having to build bitmaps....


Good point. I started out using a table and setting the background colour.
That worked fine until some people printed it and the colours didn't come
out. I realise this is down to their configuration Tools > Internet Options
Advanced > Printing with "Print background colors and images" unchecked,

but telling the users to change their settings isn't an ideal solution.

I assume that if I were to use DIVs then I would hit the same problem?
Please correct me if I'm wrong.


I don't know for sure, give it try and see....

LFS
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
Hello I'm writting an apllication and i like to display and offscreen image. However my code doesn't seem to work. It compiles and runs properly but What i want is to associate the button of the...
6
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with =====================================================================...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
7
by: Andrew Christiansen | last post by:
Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on a treeview control. I have the imagelist on the form filled with images, and have the ImageList property of the...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: kkizer | last post by:
I have a problem with this simple code below. Moving the files works perfectly, but once in a blue moon the file that it is trying to move dissapears before it can move it. and when this happens...
7
crystal2005
by: crystal2005 | last post by:
Hi all, I'm currenty creating a website. I got one confusing problem related to CSS and JavaScript actually, not really html. The problem is, I actually want my welcome screen page is to be random...
8
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as...
3
omerbutt
by: omerbutt | last post by:
hi there i have downloaded a prototype tooltip from http://www.nickstakenburg.com/projects/prototip/ the logic it uses is to call the script after creating the <div> for example i am using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.