GDI+ Question

M

m3ckon

Hi there,

was wondering if someone could help me.. I've been using GDI + to
overlay some text onto an image and it's displaying without any
problems.

However, I wanted to put the output into an image control so that I
could format it and manipulate it better.

I'm using the code below: (can someone tell me how I can either resize
the image I'm displaying or preferably how to add it to an image
control?? (please)

Public Function DisplayImage(ByVal imagepath As String)
Dim strimagepath As String
Dim strimgheight As String
Dim strimgWidth As String
Response.Clear()

strimagepath = imagepath
Dim imgOutput As New Bitmap(strimagepath)
Dim g As Graphics = Graphics.FromImage(imgOutput)

g.DrawString("Copyright 2004", New Font("verdana", 16,
FontStyle.Bold), SystemBrushes.WindowText, New PointF(2, 20))
imgOutput.Save(Response.OutputStream, ImageFormat.Jpeg) ' output
to the user

' tidy up
g.Dispose()
imgOutput.Dispose()
Response.End()
End Function
 
K

Kevin Spencer

Using a class to dynamically-generate an image in a web application is
fairly simple. You create a class that can render an image, in a format that
can be viewed in a browser (e.g. JPG, GIF, PNG). That class has a method
similar to the one you have posted, which sets the Response.ContentType to
"image/jpg" (for example), and sends the image to the Response.OutputStream,
BUT doesn't include any other code for outputting text or any other data -
just the image. the reason for this? In an HTML document, images are
embedded by putting a URL to the image in the page. The browser then
requests that URL, and displays the image in the page according to the
markup in the HTML. IOW, the image file is a separate resource from the HTML
document. This makes sense, as HTML documents are pure text, and images are
pure binary data.

One the image class has been created, you can use it in an ASPX page to
render an image, by having the ASPX page call its method for sending the
image to the page. The page has no HTML, but only sends the image to the
browser. You can now use that page's URL as an image URL in a page, or, in
your case, an image control.

Sizing the image can best be done by the class that creates the image. It
can also be done on the client browser by setting the height and/or width
attributes or styles.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top