听雨

专,静,谦,筹,悟,慎,透,恒
  博客园  :: 首页  :: 新随笔  :: 管理

使用C39HrP48DhTt字體生成條型碼

Posted on 2006-11-08 18:15  听雨  阅读(765)  评论(0编辑  收藏  举报

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