• 大小: 613KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-09
  • 语言: C#
  • 标签:

资源简介

C#热敏小票打印机打印位图,可以打印条形码和二维码还有简单的图片

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Text;
using System.Windows.Forms;


namespace LPTPrinter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //调用函数
        LptControl lc = new LptControl(“lpt1“);



        //打开端口
        private void btnOpen_Click(object sender EventArgs e)
        {
            if (txtLpt.Text.Trim() == ““)
            {
                MessageBox.Show(“LPT端口不能为空!“);
                return;
            }
            lc = new LptControl(txtLpt.Text);
            if (!lc.Open())
            {
                ShowMessage(“打开LPT端口失败!“);
                return;
            }
            btnOpen.Enabled = false;
            btnClose.Enabled = true;



        }


        //在文本中显示成功与否信息
        private void ShowMessage(string msg)
        {
            txtMessage.AppendText(msg);
            txtMessage.AppendText(“\r\n“);

        }



        /// 
        /// 关闭端口
        /// 

        /// 
        /// 
        private void btnClose_Click(object sender EventArgs e)
        {
            //调用关闭方法
            lc.Close();
            //把关闭按钮置为不可用,打开按钮置为可用
            btnOpen.Enabled = true;
            btnClose.Enabled = false;

        }

        private void Form1_Load(object sender EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender EventArgs e)
        {

        }

        /// 
        /// 打印图片方法
        /// 

        public void PrintOne()
        {
            //获取图片
            Bitmap bmp = new Bitmap(pictureBox1.Image);

            //设置字符行间距为n点行
            byte[] data = new byte[] { 0x1B 0x33 0x00 };
            
            lc.Write(data);

            data[0] = (byte)‘\x00‘;
            data[1] = (byte)‘\x00‘;
            data[2] = (byte)‘\x00‘;    // Clear to Zero.

            Color pixelColor;


            //ESC * m nL nH d1…dk   选择位图模式
            // ESC * m nL nH
            byte[] escBmp = new byte[] { 0x1B 0x2A 0x00 0x00 0x00 };

            escBmp[2] = (byte)‘\x21‘;

            //nL nH
            escBmp[3] = (byte)(bmp.Width % 256);
            escBmp[4] = (byte)(bmp.Width / 256);

            //循环图片像素打印图片
            //循环高
            for (int i = 0; i < (bmp.Height / 24 + 1); i++)
            {
                //设置模式为位图模式
                lc.Write(escBmp);
                //循环宽
                for (int j = 0; j < bmp.Width; j++)
                {
                    for (int k = 0; k < 24; k++)
                    {
                        if (((i * 24) + k) < bmp.Height)  // if within the BMP size
                        {
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....       167  2012-12-31 21:52  LPTPrinter\LPTPrinter\App.config

     文件      95744  2012-12-31 22:57  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.exe

     文件        167  2012-12-31 21:52  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.exe.config

     文件      32256  2012-12-31 22:57  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.pdb

    I.A....     22472  2012-12-31 22:57  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe

    I.A....       167  2012-12-31 21:52  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe.config

    I.A....       490  2012-06-02 22:34  LPTPrinter\LPTPrinter\bin\Debug\LPTPrinter.vshost.exe.manifest

    I.A....    120054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\200-200.bmp

    I.A....     81654  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\200.bmp

    I.A....      7759  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\230-230.jpg

    I.A....    188054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\250-250.bmp

    I.A....    127894  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\250.bmp

    I.A....     90054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300-150.bmp

    I.A....    153054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300-170.bmp

    I.A....     12054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300-2.bmp

    I.A....    270054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300-300.bmp

    I.A....    183654  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300.bmp

    I.A....    172628  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\300x.bmp

    I.A....    368254  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\350-350.bmp

    I.A....    480054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\400-400.bmp

    I.A....    326454  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\400.bmp

    I.A....     56968  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\900-900.jpg

    I.A....    193554  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\aa.bmp

    I.A....      9654  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\bb.bmp

    I.A....     60054  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\cc.bmp

    I.A....     43218  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\f858ad6bb75b99382dac54fca42a35f9.bmp

    I.A....     74588  2012-12-31 17:29  LPTPrinter\LPTPrinter\bin\Debug\picture\f858ad6bb75b99382dac54fca42a35f9.jpg

    I.A....      5017  2012-12-31 22:57  LPTPrinter\LPTPrinter\Form1.cs

    I.A....      7905  2012-12-31 17:29  LPTPrinter\LPTPrinter\Form1.Designer.cs

    I.A....    128807  2012-12-31 17:29  LPTPrinter\LPTPrinter\Form1.resx

............此处省略176个文件信息

评论

共有 条评论