Dim strFontName As String = "C39HrP48DhTt"
Dim intFontSize As Integer = 70
Dim strShowName As String = lblrma.Text.Trim
Dim objBitmap As Bitmap
Dim g As Graphics
Dim stringFont As Font = New Font(strFontName, intFontSize, FontStyle.Regular)
Dim stringFormat As StringFormat = New StringFormat
stringFormat.FormatFlags = StringFormatFlags.NoWrap
Try
Dim filename As String = "barcode.jpg"
objBitmap = New Bitmap(1, 1)
g = Graphics.FromImage(objBitmap)
Dim stringSize As SizeF = g.MeasureString(strShowName, stringFont)
Dim nWidth As Integer = CType(stringSize.Width, Integer)
Dim nHeight As Integer = CType(stringSize.Height, Integer)
g.Dispose()
objBitmap.Dispose()
objBitmap = New Bitmap(nWidth, nHeight)
g = Graphics.FromImage(objBitmap)
g.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, nWidth, nHeight))
g.DrawString(strShowName, stringFont, New SolidBrush(Color.Black), New PointF(0, 0), stringFormat)
objBitmap.Save(Server.MapPath(".") & filename, Imaging.ImageFormat.Jpeg) '----圖片的生成路徑
Catch ex As Exception
Response.Write(ex.Message)
Finally
g.Dispose()
objBitmap.Dispose()
End Try