473,320 Members | 2,000 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,320 software developers and data experts.

GDI+ Question

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
1 828
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.

"m3ckon" <an*******@devdex.com> wrote in message
news:uz**************@tk2msftngp13.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2

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

Similar topics

12
by: Charles Law | last post by:
If I draw a rectangle, 6 inches by 2 inches, on a user control with a PageUnit of Inches, I get a rectangle of 7 by 2.2 inches. Is this what people would expect? I would have hoped that it was at...
1
by: pei_world | last post by:
Hi there, I have a problem about how to keep my draw graphics stay on my control unless I delete them. that means how to resist my graphics. also how to partially remove some graphics from my...
1
by: David Sobey | last post by:
Hi I'm making a custom component using GDI+, a calendar grid thingy. I paint the grid and numbers in my overrided OnPaint. However, when i go to paint other things at other times in other...
8
by: Brian Basquille | last post by:
Hello all, Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the edges of them out using anti-aliasing. Why is it that my puck...
7
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
5
by: jack | last post by:
In using GDI+ drawstring, if the string to be drawn is in rtf format, how do I make GDI+ to recognize the rtf attributes. In other words, how do I draw one string in GDI+ , within which the...
2
by: SStory | last post by:
Question #1) If I do Image.Save with the same filepath that I got the image from, it bombs with "A generic error occurred in GDI+" Any ideas? I prompt the user before overwriting, but if they...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
1
by: Chris Dunaway | last post by:
When working with GDI+, calling the CreateGraphics method to draw on a control has normally been frowned upon and it is always emphasized to dispose of pens and brushes and other GDI objects lest...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.