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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center-aligning text using system.drawing in a given space. 1

Status
Not open for further replies.

JAG14

Programmer
Sep 26, 2003
469
0
0
GB
Hi Everyone,

I'm using system.drawing to output an overwritten image to a webpage.
I have a base image, which I then 'draw' the text on to dynamically using values from the DB.

My question is, if I have a space located in the image that is as follows, how do I get the text to center align inside that space?

Base Image 600x80 pixels
Space for text 61x61 pixels starting at top left point x10-y18.

If you need an image example, please ask. This has wasted 3 valuable hours already!

Thanks a million in advance,

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Hi Mark, Thanks for the response.
I'm using the code specified below (with mods)

Code:
<%@ page language="vb" contenttype="image/jpeg" %>  
<%@ import namespace="system.drawing" %>  
<%@ import namespace="system.drawing.imaging" %>  
<%@ import namespace="system.drawing.drawing2d" %>  
<%  
  
response.clear ' make sure Nothing has gone to the client  
  
Dim imgOutput as New System.Drawing.Bitmap(Server.MapPath("headBGVTitle.jpg"))

Dim g as graphics = graphics.fromimage(imgOutput) ' create a New graphic object from the above bmp  

g.smoothingMode = smoothingMode.antiAlias ' antialias objects  
 
' draw the number on the image canvas in verdana 18pt font bold  
g.drawString(iNoOfRooms), New font("verdana",18,fontstyle.bold),systembrushes.windowtext, New pointF(10,18))  
  
 
imgOutput.save(response.outputstream, imageformat.jpeg) ' output to the user  
 
  
' tidy up  
g.dispose()  
imgOutput.dispose()  
response.end  
 
%>

The problem lies in the fact that the 'gDrawstring' Point is only the top left corner of the space available for the text and if 'iNoOfRooms=3' it will produce a misaligned result from 'iNoOfRooms=33'

Thanks again for you help in advance.

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Mark,

You're a star, thanks man.
It looks good and i'll have a pop at it when I get back to t'office.

Thanks again!

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top