Solved

Export a label to an image

Posted on 2006-11-28
4
186 Views
Last Modified: 2008-02-01
Hi All,

Is there any way to save what is in a label i.e. the text, to an image? I have a barcode font and would like to save the text as an image. Is there a way to do this?

Thanks
0
Comment
Question by:nzfire
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 18027028
Hi nzfire,

You can build an image dynamically with the appropriate content:

Imports System.Drawing
Imports System.drawing.imaging
Imports System.drawing.drawing2d

 and then in your page_load event do:

        Dim strBarcode As String = "1234567890" 'The text to encode as the barcode

        'Get a dummy bitmap so we can work out how big the real one needs to be
        Dim b As New System.drawing.Bitmap(100, 100, PixelFormat.Format16bppRgb555)
        Dim salign As New System.drawing.StringFormat
        Dim g As Graphics = Graphics.FromImage(b)
        'determine the height and width of the barcode
        Dim w As Single = g.MeasureString(strBarcode.ToString, New Font("Free 3 Of 9 Extended", 20, FontStyle.Regular, GraphicsUnit.Point)).Width
        Dim h As Single = g.MeasureString(strBarcode.ToString, New Font("Free 3 Of 9 Extended", 20, FontStyle.Regular, GraphicsUnit.Point)).Height
        'get rid of the dummy bitmap and create a new one of the right size (add a bit to be sure if you want).
        b = Nothing
        b = New System.drawing.Bitmap(w * 1.1, h * 1.1, PixelFormat.Format16bppRgb555)
        g = Graphics.FromImage(b)
        g.SmoothingMode = SmoothingMode.AntiAlias ' antialias objects
        g.Clear(Color.White)  ' blank the image
        'Now write the barcode to the bitmap
        g.DrawString(strBarcode.ToString, New Font("Free 3 Of 9 Extended", 20, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, 0, 0)
        'Set the image to a picturebox object - you can do whatever else you need to with it here as well, such as save it to a file or whatever.
        PictureBox1.Image = b
        g = Nothing
        b = Nothing

This is an example with a freeware barcode font. You should substitute your own font above.

Tim Cottee
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18027029
nzfire,

Ignore the page_load event part, that was from an asp.net version of this, you just need to put that code in a procedure somewhere that you can call it.

Tim
0
 
LVL 10

Expert Comment

by:gangwisch
ID: 18027123
cant you do label1.drawtobitmap?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18028805
I believe DrawToBitmap() is only available in VB.Net 2005...

You could also take a screenshot of the Label:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21627632.html
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
get column names from table in vb.net 8 49
Help with consolidating excel files using VB.net 2 29
Convert datetime to time string 10 28
Generate Numbers in JQuery file 11 66
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question