C# 通过web应用程序生成条形码

C# 通过web应用程序生成条形码,c#,asp.net,web-applications,barcode,C#,Asp.net,Web Applications,Barcode,我想通过我的web应用程序生成条形码。我试图通过谷歌找到实现它的源代码,但我得到的代码是通过Windows应用程序生成条形码。但我希望代码在我的web应用程序中包含相同的功能。web应用程序的代码应该是什么?web应用程序中picturebox的替代品应该是什么 Windows应用程序的代码: using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Png); pictureBox1.I

我想通过我的web应用程序生成条形码。我试图通过谷歌找到实现它的源代码,但我得到的代码是通过Windows应用程序生成条形码。但我希望代码在我的web应用程序中包含相同的功能。web应用程序的代码应该是什么?web应用程序中picturebox的替代品应该是什么

Windows应用程序的代码:

using (MemoryStream ms = new MemoryStream())
{
    bitmap.Save(ms, ImageFormat.Png);
    pictureBox1.Image = bitmap;
    pictureBox1.Height = bitmap.Height;
    pictureBox1.Width = bitmap.Width;
}
生成条形码的代码:

private void button1_Click(object sender, EventArgs e)
{
    string barcode = textBox1.Text;

    Bitmap bitmap = new Bitmap(barcode.Length + 40, 150);

    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
        Font ofont = new System.Drawing.Font("Free 3 of 9 Extended", 40);
        PointF point = new PointF(2f, 2f);
        SolidBrush black = new SolidBrush(Color.Black);
        SolidBrush white = new SolidBrush(Color.White);
        graphics.FillRectangle(white, 0, 0, bitmap.Width, bitmap.Height);
        graphics.DrawString("*" + barcode + "*", ofont, black, point);
    }
}
这不需要任何c代码。这是一个示例html页面

<html>
<style>
    @font-face {
        font-family: barcode;
        src: url(free3of9.ttf);
    }
</style>

<body>
    ABC
    <div style='font-family:barcode;font-size:32px;'>123456789</div>
    DEF
</body>

</html>

@字体{
字体系列:条码;
src:url(free3of9.ttf);
}
基础知识
123456789
DEF
以下是输出:

这不需要任何c代码。这是一个示例html页面

<html>
<style>
    @font-face {
        font-family: barcode;
        src: url(free3of9.ttf);
    }
</style>

<body>
    ABC
    <div style='font-family:barcode;font-size:32px;'>123456789</div>
    DEF
</body>

</html>

@字体{
字体系列:条码;
src:url(free3of9.ttf);
}
基础知识
123456789
DEF
以下是输出:

您可以使用.net WebSocket服务器将图像数据发送到Web客户端。下面是一个简单的例子:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperSocket.SocketBase.Protocol;
using SuperSocket.SocketEngine;

namespace SuperSocket.QuickStart.TelnetServer
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2012)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();
            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
        }

        static void appServer_NewSessionConnected(AppSession session)
        {
            session.Send("Welcome to SuperSocket Telnet Server");
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用SuperSocket.SocketBase;
使用SuperSocket.SocketBase.Config;
使用SuperSocket.SocketBase.Logging;
使用SuperSocket.SocketBase.Protocol;
使用SuperSocket.SocketEngine;
命名空间SuperSocket.QuickStart.TelnetServer
{
班级计划
{
静态void Main(字符串[]参数)
{
WriteLine(“按任意键启动服务器!”);
Console.ReadKey();
Console.WriteLine();
var appServer=new appServer();
//安装appServer
if(!appServer.Setup(2012))//带侦听端口的安装程序
{
Console.WriteLine(“设置失败!”);
Console.ReadKey();
返回;
}
appServer.NewSessionConnected+=新会话处理程序(appServer_NewSessionConnected);
Console.WriteLine();
//尝试启动appServer
如果(!appServer.Start())
{
Console.WriteLine(“启动失败!”);
Console.ReadKey();
返回;
}
WriteLine(“服务器已成功启动,请按“q”键停止它!”);
while(Console.ReadKey().KeyChar!=“q”)
{
Console.WriteLine();
继续;
}
Console.WriteLine();
//停止appServer
appServer.Stop();
WriteLine(“服务器已停止!”);
}
静态无效appServer_NewSessionConnect(AppSession会话)
{
Send(“欢迎使用SuperSocket Telnet服务器”);
}
}
}
您可以使用会话发送图像数据。send()。 然后创建一个div元素并用JavaScript绘制图像:

var ws = new WebSocket("ws://127.0.0.1:2012/");  
ws.onmessage = function (evt) {     
    var bytes = new Uint8Array(evt.data);
    var data = "";
    var len = bytes.byteLength;
    for (var i = 0; i < len; ++i) {
        data += String.fromCharCode(bytes[i]);
    }
    var img = document.getElementById("image");
    img.src = "data:image/png;base64,"+window.btoa(data);   
}; 
var ws=new-WebSocket(“ws://127.0.0.1:2012/”;
ws.onmessage=函数(evt){
var bytes=新的Uint8Array(evt.data);
var数据=”;
var len=字节数。字节长度;
对于(变量i=0;i
您可以使用.net WebSocket服务器将图像数据发送到Web客户端。下面是一个简单的例子:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperSocket.SocketBase.Protocol;
using SuperSocket.SocketEngine;

namespace SuperSocket.QuickStart.TelnetServer
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2012)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();
            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
        }

        static void appServer_NewSessionConnected(AppSession session)
        {
            session.Send("Welcome to SuperSocket Telnet Server");
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用SuperSocket.SocketBase;
使用SuperSocket.SocketBase.Config;
使用SuperSocket.SocketBase.Logging;
使用SuperSocket.SocketBase.Protocol;
使用SuperSocket.SocketEngine;
命名空间SuperSocket.QuickStart.TelnetServer
{
班级计划
{
静态void Main(字符串[]参数)
{
WriteLine(“按任意键启动服务器!”);
Console.ReadKey();
Console.WriteLine();
var appServer=new appServer();
//安装appServer
if(!appServer.Setup(2012))//带侦听端口的安装程序
{
Console.WriteLine(“设置失败!”);
Console.ReadKey();
返回;
}
appServer.NewSessionConnected+=新会话处理程序(appServer_NewSessionConnected);
Console.WriteLine();
//尝试启动appServer
如果(!appServer.Start())
{
Console.WriteLine(“启动失败!”);
Console.ReadKey();
返回;
}
WriteLine(“服务器已成功启动,请按“q”键停止它!”);
while(Console.ReadKey().KeyChar!=“q”)
{
Console.WriteLine();
继续;
}
Console.WriteLine();
//停止appServer
appServer.Stop();
WriteLine(“服务器已停止!”);
}
静态无效appServer_NewSessionConnect(AppSession会话)
{
Send(“欢迎使用SuperSocket Telnet服务器”);
}
}
}
您可以使用会话发送图像数据。send()。 然后创建一个div元素并用JavaScript绘制图像:

var ws = new WebSocket("ws://127.0.0.1:2012/");  
ws.onmessage = function (evt) {     
    var bytes = new Uint8Array(evt.data);
    var data = "";
    var len = bytes.byteLength;
    for (var i = 0; i < len; ++i) {
        data += String.fromCharCode(bytes[i]);
    }
    var img = document.getElementById("image");
    img.src = "data:image/png;base64,"+window.btoa(data);   
}; 
var ws=new-WebSocket(“ws://127.0.0.1:2012/”;
ws.onmessage=函数(evt){
var bytes=新的Uint8Array(evt.data);
var数据=”;
var len=字节数。字节长度;
对于(变量i=0;i