using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;




namespace Chamc.EquipmentManage.UI
{
    public partial class Form4 : Form
    {
       
        
        public Form4()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MicSoft.PDF417 pdf417 = new MicSoft.PDF417();
            //pdf417.Data = "I love You";
            //pdf417.SetSize(500, 300);
            //pdf417.SaveAsImage("d:\\pdf417sss.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //
            string content = "test";
            byte[] b = System.Text.Encoding.Default.GetBytes(content);
            Make(b, b.Length, @"temp\temp11.bmp", 5, 3, 3);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string filePath = @"D:\Project\chamc\Chamc.EquipmentManage\Chamc.EquipmentManage.UI\bin\Debug\temp\temp11.bmp";
            Byte[] b = new byte[1024];
            int clen = Dec(filePath, b,1024);
            string sssd = "";
        }
        #region PDF417编码、解码动态连接库中方法声明
        
        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="ucData">条码数据</param>
        /// <param name="nDataLen">条码数据长度(注:是字节数) 长度<=1K</param>
        /// <param name="szBmpFileName">生成条码的图片文件名，BMP格式</param>
        /// <param name="nClumn">条码列数，取值范围1-30，根据具体数据字符串长度</param>
        /// <param name="nErr">纠错等级，取值范围0-7，建议取2-3</param>
        /// <param name="nHLRatio">条码单位长度和宽度比例，取值范围1-5；
        ///          1----紧凑型条码，生成条码图片容量最小，适合配合数据库管理系统使用，
        ///                便于直接以最小的容量存储在数据库中，而且生成速度最快，适合大
        ///                批量生成条码。但需要通过报表控件做纵横向适当拉伸后，打印出来
        ///                才可识读，不能直接打印识读或软解码；
        ///           2--5 标准型条码，适合直接打印识读或软件解码，建议取3</param>
        [DllImport("MakeBar.dll")]
        public static extern void Make(byte[] ucData, int nDataLen, string szBmpFileName, int nClumn, int nErr, int nHLRatio);

        /// <summary>
        /// 解码
        /// </summary>
        /// <param name="szBarFileName">存放PDF417的二维条码的图片</param>
        /// <param name="byDecData">解码后存放数据的变量  是BYTE数组 需预先分配空间</param>
        /// <param name="nLen">byDecData的长度</param>
        /// <returns>>0 成功解码后返回的数据长度;0 解码失败;-2 BYTE数组空间不够</returns>
        [DllImport("DecBarPDF417.dll")]
        public static extern int Dec(string szBarFileName, byte[] byDecData, int nLen);
        #endregion
    }
}