2016-03-07 154 views
0

我嘗試使用字符串顯示條形碼,我有這樣的字符串:SO-123456 但不顯示帶有條形碼的圖像。爲什麼不顯示我的條碼?

我的代碼是:

Imports System.Drawing 
Imports System.Drawing.Imaging 
Imports System.IO 

Partial Class VB 
    Inherits System.Web.UI.Page 
    Protected Sub btnGenerate_Click(sender As Object, e As EventArgs) 
     Dim barCode As String = txtCode.Text 
     Dim imgBarCode As New System.Web.UI.WebControls.Image() 
     Using bitMap As New Bitmap(barCode.Length * 40, 80) 
      Using graphics__1 As Graphics = Graphics.FromImage(bitMap) 
       Dim oFont As New Font("IDAutomationHC39M", 16) 
       Dim point As New PointF(2.0F, 2.0F) 
       Dim blackBrush As New SolidBrush(Color.Black) 
       Dim whiteBrush As New SolidBrush(Color.White) 
       graphics__1.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height) 
       graphics__1.DrawString("*" & barCode & "*", oFont, blackBrush, point) 
      End Using 
      Using ms As New MemoryStream() 
       bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png) 
       Dim byteImage As Byte() = ms.ToArray() 

       Convert.ToBase64String(byteImage) 
       imgBarCode.ImageUrl = "data:image/png;base64," & Convert.ToBase64String(byteImage) 
      End Using 
      plBarCode.Controls.Add(imgBarCode) 
     End Using 
    End Sub 
End Class 

和圖形頁面是:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:TextBox ID="txtCode" runat="server"></asp:TextBox> 
    <asp:Button ID="btnGenerate" runat="server" Text="Generate" 
     onclick="btnGenerate_Click" /> 
    <hr /> 
    <asp:PlaceHolder ID="plBarCode" runat="server" /> 
    </form> 
</body> 
</html> 

如何獲得IDAutomationHC39M正確,可我把一個文件夾中,我嘗試打開代碼吧?我不知道

我想的是: enter image description here

但我顯示:

enter image description here

+1

現在看起來我的代碼,我把2張圖片看到差異 – Vladut

+2

我會說IDAutomationHC39M沒有安裝在你正在運行它的地方,需要是Windows下的字體文件夾。 –

+0

如果在我放置我的文件的服務器上使用它? – Vladut

回答

1
Dim oFont As New Font("IDAutomationHC39M", 16) 

需求,成爲

Dim privateFonts As New System.Drawing.Text.PrivateFontCollection() 
privateFonts.AddFontFile("C:\Documents and Settings\somefont.ttf") 
Dim oFont As New System.Drawing.Font(privateFonts.Families(0), 12) 
+1

Greate,完美的工作,非常感謝@Mike! – Vladut