⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encodeform.cs

📁 PDF417,QR_CODE,DATAMATRIX的控件和例子
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime .InteropServices ;
using System.Drawing .Imaging ;



public class EncodeForm : System.Windows.Forms.Form
{
	#region procedure declarations, constant definitions and macros
	/*Image file reading/writing APIs and definitions */
	//DEFINES SECTION 
	public const int  PT_IMAGERW_FAIL               = 0x00000000; //An error occurred in an operation.
	public const int  PT_IMAGERW_SUCCESS            = 0x00000001; //An operation is successful.
	public const int  PT_IMAGERW_ALLOC_ERROR        = 0x00000100; //Error while allocating memory.
	public const int  PT_IMAGERW_FORMAT_UNSUPPORTED = 0x00000101; //The format of image is unsupported. 
	
	//STRUCTURES SECTION
	unsafe public struct PTIMAGE
	{
		public int            dwWidth;       //The width of the image in pixels.
		public int            dwHeight;      //The height of the image in pixels.
		public byte*          pBits;         //Pointer to the image data.
		public byte*          pPalette;      //Pointer to the palette data (RGBQUAD)for 1,4,8 bits image.
		public short          wBitsPerPixel; //Number of bits per pixel.
	}
		
	//FUNCTIONS SECTION	
	[DllImport("PtImageRW.dll", EntryPoint="PtInitImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern void PtInitImage( ref PTIMAGE pImage );
	
	[DllImport("PtImageRW.dll", EntryPoint="PtLoadImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern int PtLoadImage( string filename, ref PTIMAGE pImage, int FrameIndex );

	[DllImport("PtImageRW.dll", EntryPoint="PtSaveImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern int PtSaveImage( string filename, ref PTIMAGE pImage );

	[DllImport("PtImageRW.dll", EntryPoint="PtShowImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern void PtShowImage( ref PTIMAGE pImage, IntPtr hDC, int x, int y, float scale );

	[DllImport("PtImageRW.dll", EntryPoint="PtCreateImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern int PtCreateImage( ref	PTIMAGE pImage, int ImageSize, int PaletteSize );

	[DllImport("PtImageRW.dll", EntryPoint="PtFreeImage", SetLastError=true,
		 CharSet=CharSet.Ansi , ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall )]
	public static extern void PtFreeImage( ref PTIMAGE pImage );

	/*PDF417 symbol writing APIs and definitions.*/
	//DEFINES SECTION
	public const int  PT_PDF417ENCODE_FAIL         = 0x00000000; //An operation is Failed.
	public const int  PT_PDF417ENCODE_SUCCESS      = 0x00000001; //An operation is successful.
	public const int  PT_PDF417ENCODE_ALLOC_ERROR  = 0x00000200; //Error while allocating the memory.
	public const int  PT_PDF417ENCODE_DATA_BIG     = 0x00000201; //Data to be encoded is too big. 
	public const int  PT_PDF417ENCODE_SIZE_SMALL   = 0x00000202; //The size of image to be pasted the symbol is too small. 
	public const int  PT_PDF417ENCODE_IMAGE_INVALID= 0x00000203; //The image to be pasted is invalid.

	public const int PT_PDF417_ECCLEVEL_0         = 0x0000; //Use ECC level 0. This uses 2   codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_1         = 0x0001; //Use ECC level 1. This uses 4   codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_2         = 0x0002; //Use ECC level 2. This uses 8   codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_3         = 0x0003; //Use ECC level 3. This uses 16  codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_4         = 0x0004; //Use ECC level 4. This uses 32  codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_5         = 0x0005; //Use ECC level 5. This uses 64  codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_6         = 0x0006; //Use ECC level 6. This uses 128 codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_7         = 0x0007; //Use ECC level 7. This uses 256 codewords for error correction.
	public const int PT_PDF417_ECCLEVEL_8         = 0x0008; //Use ECC level 8. This uses 512 codewords for error correction.
	public const int PT_PDF417_ECC_PERCENT        = 0x0009; //Use the percentage to determine the ECC level.
	
	//STRUCTURES SECTION
	public unsafe struct PTPDF417ENCODE
	{
		unsafe public byte *pData;             //Pointer to the data to be encoded.		public int         nDataLength;        //Length of the data in bytes.		public int         bIsTruncated;       //Writes truncated PDF417 symbols or not.		public short       wEccPercent;        //Determines the error correction level by percentage.		public short       wEccLevel;          //Determines the ECC level for encoding a PDF417 symbol.		public short       wCols;              //Number of columns in the symbol. 		public short       wRows;              //Number of rows in the symbol.		public short       wAspectHeigh;       //The height part of the aspect ratio of the symbol.		public short       wAspectWidth;       //The width part of the aspect ratio of the symbol. 		public short       wXModule;           //The smallest element width in pixels.		public short       wModuleAspectRatio; //The ratio of a row height to XModule.		public short       wLeftSpace;         //The left   space of the symbol in pixels while generating the image. 		public short       wRightSpace;        //The right  space of the symbol in pixels while generating the image.		public short       wTopSpace;          //The top    space of the symbol in pixels while generating the image.		public short       wBottomSpace;       //The bootom space of the symbol in pixels while generating the image.
	}

	//FUNCTIONS SECTION
	[DllImport("PtPDF417Encode.dll", EntryPoint="PtPDF417EncodeRegister",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtPDF417EncodeRegister( string KeyStr );

	[DllImport("PtPDF417Encode.dll", EntryPoint="PtPDF417EncodeInit",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtPDF417EncodeInit( ref PTPDF417ENCODE pEncode );

	[DllImport("PtPDF417Encode.dll", EntryPoint="PtPDF417Encode",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern int PtPDF417Encode( ref PTPDF417ENCODE pEncode, ref PTIMAGE pImage );

	[DllImport("PtPDF417Encode.dll", EntryPoint="PtPDF417EncodeToImage",  SetLastError=true,
		CharSet=CharSet.Ansi, ExactSpelling=true,
		CallingConvention=CallingConvention.StdCall)]
	public static extern int PtPDF417EncodeToImage( ref PTPDF417ENCODE pEncode,	ref PTIMAGE pDstImage, 	int StartX,  int StartY );

	
	/*QR Code symbol writing APIs and definitions.*/
	//DEFINES SECTION
	public const int  PT_QRENCODE_FAIL             = 0x00000000; //An operation is Failed.
    public const int  PT_QRENCODE_SUCCESS          = 0x00000001; //An operation is successful.
    public const int  PT_QRENCODE_ALLOC_ERROR      = 0x00000200; //Error while allocating the memory.
    public const int  PT_QRENCODE_DATA_BIG         = 0x00000201; //Data to be encoded is too big. 
    public const int  PT_QRENCODE_SIZE_SMALL       = 0x00000202; //The size of image to be pasted the symbol is too small. 
    public const int  PT_QRENCODE_IMAGE_INVALID    = 0x00000203; //The image to be pasted is invalid. 
    
	public const int  PT_QR_ECCLEVEL_L	        = 0x0001; //Use ECC level L. (7% ) 
    public const int  PT_QR_ECCLEVEL_M          = 0x0000; //Use ECC level M. (15%)
    public const int  PT_QR_ECCLEVEL_Q          = 0x0003; //Use ECC level Q. (25%)
    public const int  PT_QR_ECCLEVEL_H	        = 0x0002; //Use ECC level H. (30%)
    
	public const int  PT_QR_VERSION_AUTO        = 0x0000; //Determine the version by the engine,then use the smallest version that can contain the data.
    public const int  PT_QR_MASKNUMBER_AUTO     = 0x0008; //Determine the mask number by the engine.
 
	//STRUCTURES SECTION
	public unsafe struct PTQRENCODE
	{
		unsafe public byte *pData;        //Pointer to the data to be encoded.		public int         nDataLength;   //Length of the data in bytes.		public short       wVersion;      //The version of the QR Code.		public short       wMaskNumber;   //The mask number of the QR Code		public short       wEccLevel;     //Determines the ECC level for encoding a QR Code symbol.		public short       wModule;       //The size of one module in pixels.		public short       wGroupTotal;   //The number of symbols that belong to the group.		public short       wGroupIndex;   //The index of the symbol in the group,		public short       wLeftSpace;    //The left   space of the symbol in pixels while generating the image.		public short       wRightSpace;   //The right  space of the symbol in pixels while generating the image.		public short       wTopSpace;     //The top    space of the symbol in pixels while generating the image.		public short       wBottomSpace;  //The right  space of the symbol in pixels while generating the image.
	}

	//FUNCTIONS SECTION
	[DllImport("PtQREncode.dll", EntryPoint="PtQREncodeRegister",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtQREncodeRegister( string KeyStr );

	[DllImport("PtQREncode.dll", EntryPoint="PtQREncodeInit",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtQREncodeInit( ref PTQRENCODE pEncode );

	[DllImport("PtQREncode.dll", EntryPoint="PtQREncode",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern int PtQREncode( ref PTQRENCODE pEncode, ref PTIMAGE pImage );

	[DllImport("PtQREncode.dll", EntryPoint="PtQREncodeToImage",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern int PtQREncodeToImage( ref PTQRENCODE pEncode,	ref PTIMAGE pDstImage, 	int StartX,  int StartY );

	
	/*Data Matrix symbol writing APIs and definitions.*/
	//DEFINES SECTION
	public const int  PT_DMENCODE_FAIL             = 0x00000000; //An operation is Failed.
	public const int  PT_DMENCODE_SUCCESS          = 0x00000001; //An operation is successful.
	public const int  PT_DMENCODE_ALLOC_ERROR      = 0x00000200; //Error while allocating the memory.
	public const int  PT_DMENCODE_DATA_BIG         = 0x00000201; //Data to be encoded is too big. 
	public const int  PT_DMENCODE_SIZE_SMALL       = 0x00000202; //The size of image to be pasted the symbol is too small. 
	public const int  PT_DMENCODE_IMAGE_INVALID    = 0x00000203; //The image to be pasted is invalid. 
	
	public const int PT_DM_SQUARE_AUTO    =0;  //Use the smallest square size thatcan contain the data.
    public const int PT_DM_10x10          =1;  //Data Matrix Type 10x10.
	public const int PT_DM_12x12          =2;  //Data Matrix Type 12x12.
	public const int PT_DM_14x14          =3;  //Data Matrix Type 14x14.
	public const int PT_DM_16x16          =4;  //Data Matrix Type 16x16.
	public const int PT_DM_18x18          =5;  //Data Matrix Type 18x18.
	public const int PT_DM_20x20          =6;  //Data Matrix Type 20x20.
	public const int PT_DM_22x22          =7;  //Data Matrix Type 22x22.
	public const int PT_DM_24x24          =8;  //Data Matrix Type 24x24.
	public const int PT_DM_26x26          =9;  //Data Matrix Type 26x26.
	public const int PT_DM_32x32          =10; //Data Matrix Type 32x32.
	public const int PT_DM_36x36          =11; //Data Matrix Type 36x36.
	public const int PT_DM_40x40          =12; //Data Matrix Type 40x40.
	public const int PT_DM_44x44          =13; //Data Matrix Type 44x44.
	public const int PT_DM_48x48          =14; //Data Matrix Type 48x48.
	public const int PT_DM_52x52          =15; //Data Matrix Type 52x52.
	public const int PT_DM_64x64          =16; //Data Matrix Type 64x64.
	public const int PT_DM_72x72          =17; //Data Matrix Type 72x72.
	public const int PT_DM_80x80          =18; //Data Matrix Type 80x80.
	public const int PT_DM_88x88          =19; //Data Matrix Type 88x88.
	public const int PT_DM_96x96          =20; //Data Matrix Type 96x96.
	public const int PT_DM_104x104        =21; //Data Matrix Type 104x104.
	public const int PT_DM_120x120        =22; //Data Matrix Type 120x120.
	public const int PT_DM_132x132        =23; //Data Matrix Type 132x132.
	public const int PT_DM_144x144        =24; //Data Matrix Type 144x144.
	public const int PT_DM_8x18           =25; //Data Matrix Type 8x18.
	public const int PT_DM_8x32           =26; //Data Matrix Type 8x32.
	public const int PT_DM_12x26          =27; //Data Matrix Type 12x26.
	public const int PT_DM_12x36          =28; //Data Matrix Type 12x36.
	public const int PT_DM_16x36          =29; //Data Matrix Type 16x36.
	public const int PT_DM_16x48          =30; //Data Matrix Type 16x48.
	public const int PT_DM_RECTANGLE_AUTO =31; //use the smallest rectangular size that can contain the data.

	
	//STRUCTURES SECTION
	public unsafe struct PTDMENCODE
	{
		unsafe public byte *pData;        //Pointer to the data to be encoded.		public int         nDataLength;   //Length of the data in bytes.		public short       wSymbolSize;   //The symbol size.		public short       wModule;       //The size of one module in pixels.		public short       wGroupTotal;   //The number of symbols that belong to the group.		public short       wGroupIndex;   //The index of the symbol in the group		public short       wFileIDHigh;   //The high byte of the file ID number.		public short       wFileIDLow;    //The low byte of the file ID number.		public short       wLeftSpace;    //The left   space of the symbol in pixels while generating the image. 		public short       wRightSpace;   //The right  space of the symbol in pixels while generating the image. 		public short       wTopSpace;     //The top    space of the symbol in pixels while generating the image. 		public short       wBottomSpace;  //The bottom space of the symbol in pixels while generating the image. 
	}

	//FUNCTIONS SECTION
	[DllImport("PtDMEncode.dll", EntryPoint="PtDMEncodeRegister",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtDMEncodeRegister( string KeyStr );

	[DllImport("PtDMEncode.dll", EntryPoint="PtDMEncodeInit",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern void PtDMEncodeInit( ref PTDMENCODE pEncode );

	[DllImport("PtDMEncode.dll", EntryPoint="PtDMEncode",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern int PtDMEncode( ref PTDMENCODE pEncode, ref PTIMAGE pImage );

	[DllImport("PtDMEncode.dll", EntryPoint="PtDMEncodeToImage",  SetLastError=true,
		 CharSet=CharSet.Ansi, ExactSpelling=true,
		 CallingConvention=CallingConvention.StdCall)]
	public static extern int PtDMEncodeToImage( ref PTDMENCODE pEncode,	ref PTIMAGE pDstImage, 	int StartX,  int StartY );

    #endregion


	private   System.ComponentModel.Container components = null; 
	private   System.Windows.Forms.TextBox StrTextBox;
	private   System.Windows.Forms.PictureBox BarPicBox; 
	private   System.Windows.Forms.Button EncodePDF417Btn;
	private   System.Windows.Forms.Button EncodeQRBtn;
	private   System.Windows.Forms.Button EncodeDataMatrixBtn; 

	private   PTIMAGE                m_image;
	private   PTPDF417ENCODE         m_PDF417Encode ;
	private   PTQRENCODE             m_QREncode ;
	private   PTDMENCODE             m_DMEncode ;
	private   Image                  m_BarcodeImg;
	private   Image                  m_BlankImg;		
		
	#region windows procedure

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -