0

大家早上好/下午,我一直在测试 vin 扫描仪BarcodeLib,最后使用 Visual Studio 2012 让它工作。

在我将图像硬编码到阅读器之前

string[] results = BarcodeReader.read(@"C:/scan/image.jpg", BarcodeReader.CODE39);

但现在因为我想input type在我的 asp 中使用 a,它停止显示结果。

我的问题是,为什么此时它根本不输出任何东西?

我的想法是,也许它是 if 语句。

这里的编码

namespace testWebBarcode
{
      protected void bnvinoneclick_Click(object sender, EventArgs e)
        {
           HttpPostedFile fileImage = Request.Files["FileUpload"];

            if (fileImage != null && fileImage.ContentLength > 0)
             {
               string imageFileName = Path.GetFileName(fileImage.FileName);

                //reads barcode (@"filename", BarcodeReader.TypeBarcode)
                string[] results = BarcodeReader.read(imageFileName, BarcodeReader.CODE39);
                string answer = string.Empty;
                for (int i = 0; i < results.Length; i++)
                     {
                       answer = results[i];
                     }
               string finalVin = "The vin is: " + answer;
               lblvin.Text = finalVin;
             }

        }

}

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testWebBarcode._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
   <script type="text/javascript">
       function readURL() 
          {

           document.getElementById('<%=bnvinoneclick.ClientID%>').click();
          }

   </script>


</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <p>
        <asp:Label ID="lblvin" runat="server" Text=""></asp:Label>
    </p>
    <p>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </p>
    <p>

       <input type="file" accept="image/*" runat="server" id="FileUpload" onchange="readURL();" />



        <asp:Button ID="bnvinoneclick" runat="server" Text="Check vin" 
            onclick="bnvinoneclick_Click" />
            </p>

</asp:Content>

感谢您花时间查看我的问题,如果您回复了

4

2 回答 2

0

在您的第一个“工作”示例中,您正在使用文件系统路径读取图像(即从文件系统中读取文件)

在第二个示例中,您从HttpPostedFile对象传递文件名。您需要在此处读取输入流的内容-我的猜测是条形码读取方法正在尝试在文件系统中查找文件并且不能..?

读取HttpPostedFile输入流的内容,然后将其保存到磁盘并从那里读取,如果您不能简单地将字节数组传递给条形码库的读取方法

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx

于 2013-03-29T16:56:14.800 回答
0

您可能会发现它为您提供了客户端fileImage.FileName上文件的名称,因此您无法在服务器中使用它(注意您的 .NET 代码在服务器端而不是客户端执行)。而您可能想要的是:

  1. User uploads file from say C:\MyFiles\uploadme.jpg (this it the path you will likely get when you use the FileName property in your code)
  2. You save file to your server (e.g. to a D:\<MyServerDirectory>\UploadedImages folder or something like that)
  3. You work with the file once it's saved to the server

I would suggest saving it (see this for an example) and then passing the path of where you saved it to (considering that it now the "server" path vs. the client path) to your Barcode method

于 2013-03-29T16:59:21.593 回答