Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Export a label to an image

Posted on 2006-11-28
4
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 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 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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