【问题标题】:Why doesn't display my bar code?为什么不显示我的条形码?
【发布时间】:2016-03-09 01:01:18
【问题描述】:

我尝试用字符串显示条形码,我有这样的字符串: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,我可以放入一个文件夹并尝试打开该代码栏吗?我不知道

我想要:

但我显示:

【问题讨论】:

  • 现在看我的代码,我放了 2 张图片来看看区别
  • 我说你运行的地方没有安装IDAutomationHC39M,需要是Windows下的Fonts文件夹。
  • 如果在我放置文件的服务器上使用它?
  • 我可以从文件夹中读取这个 IDAutomationHC39M 吗?
  • 是的,请参阅 msdn.microsoft.com/en-us/library/y505zzfw.aspx 创建 PrivateFontCollection 并尝试。

标签: vb.net


【解决方案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)

【讨论】:

    猜你喜欢
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    相关资源
    最近更新 更多