Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using Drawstring to have text with filled rectangle and border?

Reply
Thread Tools

Using Drawstring to have text with filled rectangle and border?

 
 
Mark B
Guest
Posts: n/a
 
      07-10-2009
In ASP.NET VB.NET, I have a variable, strMyText that can be any text up to 255 characters.

I want be able to create a bitmap that has the text inside a bordered rectangle like these:



So the rectangle needs to stretch depending on the text length.

If anyone can help me out with the code in fGetNewLabelImage below I appreciate it.

I have made a start using another example I had but am trying to figure where to go next with it:


--------------------------------------------------------------------------------


The default.aspx page (which is used as the image source for an image-control in any other page):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="display.aspx.vb" Inherits="pages_new_label" Theme="" StyleSheetTheme="" %>


--------------------------------------------------------------------------------


The default.aspx.vb page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Response.ContentType = "image/png"
Response.BufferOutput = True

Dim bmp As Bitmap = fGetNewLabelImage()
Dim ms As MemoryStream = New MemoryStream()

bmp.Save(ms, ImageFormat.Png)
ms.WriteTo(Response.OutputStream)

bmp.Dispose()
Response.Flush()

End Sub


Public Function fGetNewLabelImage() As Image

Dim imgBackground As Bitmap
Dim g As Graphics = Graphics.FromImage(imgBackground)

g.SmoothingMode = SmoothingMode.HighQuality
Dim rectangleFont8 As New Font("Arial", 8, FontStyle.Regular)
g.DrawString("Hello", rectangleFont8, Brushes.Black, 5, 5)

g.Dispose()
Return imgBackground

End Function


--------------------------------------------------------------------------------




 
Reply With Quote
 
 
 
 
Andrew Morton
Guest
Posts: n/a
 
      07-10-2009
"Mark B" wrote
> In ASP.NET VB.NET, I have a variable, strMyText that can be any text up to
> 255 characters.
> I want be able to create a bitmap that has the text inside a bordered
> rectangle like these:
> So the rectangle needs to stretch depending on the text length.


I think using Graphics.MeasureString will enable you to determine the size
of the rectangle to create.

Andrew

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to display multiline content using java drawString() method theAndroidGuy Java 7 05-11-2009 04:29 PM
J2ME - drawString font related question Dave Ekhaus Java 3 05-10-2005 11:41 AM
Re: drawString with special Unicode characters to Graphics object Chris Smith Java 1 05-31-2004 07:33 PM
No Focused View on DrawString Xiaolei Li Java 3 04-18-2004 03:59 AM
Special characters with DrawString?! Jonah Olsson ASP .Net 3 10-03-2003 07:03 AM



Advertisments