📄 encodeform.cs
字号:
public EncodeForm()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.StrTextBox = new System.Windows.Forms.TextBox();
this.EncodePDF417Btn = new System.Windows.Forms.Button();
this.BarPicBox = new System.Windows.Forms.PictureBox();
this.EncodeQRBtn = new System.Windows.Forms.Button();
this.EncodeDataMatrixBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// StrTextBox
//
this.StrTextBox.Location = new System.Drawing.Point(43, 432);
this.StrTextBox.Multiline = true;
this.StrTextBox.Name = "StrTextBox";
this.StrTextBox.Size = new System.Drawing.Size(928, 82);
this.StrTextBox.TabIndex = 1;
this.StrTextBox.Text = "Hello World!";
//
// EncodePDF417Btn
//
this.EncodePDF417Btn.Location = new System.Drawing.Point(248, 545);
this.EncodePDF417Btn.Name = "EncodePDF417Btn";
this.EncodePDF417Btn.Size = new System.Drawing.Size(152, 31);
this.EncodePDF417Btn.TabIndex = 2;
this.EncodePDF417Btn.Text = "Encode PDF417";
this.EncodePDF417Btn.Click += new System.EventHandler(this.EncodePDF417Btn_Click);
//
// BarPicBox
//
this.BarPicBox.BackColor = System.Drawing.SystemColors.Window;
this.BarPicBox.Location = new System.Drawing.Point(43, 41);
this.BarPicBox.Name = "BarPicBox";
this.BarPicBox.Size = new System.Drawing.Size(928, 370);
this.BarPicBox.TabIndex = 3;
this.BarPicBox.TabStop = false;
//
// EncodeQRBtn
//
this.EncodeQRBtn.Location = new System.Drawing.Point(480, 544);
this.EncodeQRBtn.Name = "EncodeQRBtn";
this.EncodeQRBtn.Size = new System.Drawing.Size(144, 31);
this.EncodeQRBtn.TabIndex = 4;
this.EncodeQRBtn.Text = "Encode QR";
this.EncodeQRBtn.Click += new System.EventHandler(this.EncodeQRBtn_Click);
//
// EncodeDataMatrixBtn
//
this.EncodeDataMatrixBtn.Location = new System.Drawing.Point(696, 544);
this.EncodeDataMatrixBtn.Name = "EncodeDataMatrixBtn";
this.EncodeDataMatrixBtn.Size = new System.Drawing.Size(160, 31);
this.EncodeDataMatrixBtn.TabIndex = 5;
this.EncodeDataMatrixBtn.Text = "Encode DataMatrix";
this.EncodeDataMatrixBtn.Click += new System.EventHandler(this.EncodeDataMatrixBtn_Click);
//
// EncodeForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(1045, 604);
this.Controls.Add(this.EncodeDataMatrixBtn);
this.Controls.Add(this.EncodeQRBtn);
this.Controls.Add(this.BarPicBox);
this.Controls.Add(this.EncodePDF417Btn);
this.Controls.Add(this.StrTextBox);
this.Name = "EncodeForm";
this.Text = "Encode";
this.Load += new System.EventHandler(this.EncodeForm_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new EncodeForm());
}
private void EncodeForm_Load(object sender, System.EventArgs e)
{
PtPDF417EncodeRegister("12345678901234567890");//use the license key of demo version.
PtQREncodeRegister ("12345678901234567890");//use the license key of demo version.
PtDMEncodeRegister ("12345678901234567890");//use the license key of demo version.
PtInitImage(ref m_image);
}
unsafe private void EncodePDF417Btn_Click(object sender, System.EventArgs e)
{
int lRet;
PtPDF417EncodeInit(ref m_PDF417Encode );
string str = StrTextBox .Text ;
//convert 2 bytes unicode to 1 byte char
/*byte []arrData = new byte [2*str.Length ];
int DataLen=0;
for( int i=0; i<str.Length; i++)
{
arrData[DataLen++] = (byte)(str[i]&0x00ff);
if( (str[i]&0xff00) !=0 )
arrData[DataLen++] = (byte)( (str[i]&0xff00)>>8 );
}
m_PDF417Encode.nDataLength = DataLen ;*/
byte []arrData = new byte [str.Length ];
for( int i=0; i<str.Length; i++)
arrData[i] = (byte)(str[i]);
m_PDF417Encode.nDataLength = str.Length;
///////////////////////////////////////////
fixed(byte* p = arrData)
{
m_PDF417Encode.pData = p;
}
lRet = PtPDF417Encode( ref m_PDF417Encode, ref m_image );
if( lRet != PT_PDF417ENCODE_SUCCESS)
{
MessageBox.Show ("Encode error!" );
return;
}
if( BarPicBox.Image != m_BlankImg )//clear BarPicBox
{
BarPicBox.Image = m_BlankImg;
m_BarcodeImg.Dispose();
}
lRet = PtSaveImage( "tempPDF417.bmp", ref m_image );
if(lRet != PT_IMAGERW_SUCCESS)
{
MessageBox.Show ("Save file error");
}
else
{
m_BarcodeImg = new Bitmap("tempPDF417.bmp");
BarPicBox.Image = m_BarcodeImg;
}
PtFreeImage(ref m_image);
}
unsafe private void EncodeQRBtn_Click(object sender, System.EventArgs e)
{
int lRet;
PtQREncodeInit(ref m_QREncode );
string str = StrTextBox .Text ;
//convert 2 bytes unicode to 1 byte char
/*byte []arrData = new byte [2*str.Length ];
int DataLen=0;
for( int i=0; i<str.Length; i++)
{
arrData[DataLen++] = (byte)(str[i]&0x00ff);
if( (str[i]&0xff00) !=0 )
arrData[DataLen++] = (byte)( (str[i]&0xff00)>>8 );
}
m_QREncode.nDataLength = DataLen ;*/
byte []arrData = new byte [str.Length ];
for( int i=0; i<str.Length; i++)
arrData[i] = (byte)(str[i]);
m_QREncode.nDataLength = str.Length;
///////////////////////////////////////////
fixed(byte* p = arrData)
{
m_QREncode.pData = p;
}
lRet = PtQREncode( ref m_QREncode, ref m_image );
if( lRet != PT_QRENCODE_SUCCESS)
{
MessageBox.Show ("Encode error!" );
return;
}
if( BarPicBox.Image != m_BlankImg )//clear BarPicBox
{
BarPicBox.Image = m_BlankImg;
m_BarcodeImg.Dispose();
}
lRet = PtSaveImage( "tempQRCode.bmp", ref m_image );
if(lRet != PT_IMAGERW_SUCCESS)
{
MessageBox.Show ("Save file error");
}
else
{
m_BarcodeImg = new Bitmap("tempQRCode.bmp");
BarPicBox.Image = m_BarcodeImg;
}
PtFreeImage(ref m_image);
}
unsafe private void EncodeDataMatrixBtn_Click(object sender, System.EventArgs e)
{
int lRet;
PtDMEncodeInit(ref m_DMEncode );
string str = StrTextBox .Text ;
//convert 2 bytes unicode to 1 byte char
/*byte []arrData = new byte [2*str.Length ];
int DataLen=0;
for( int i=0; i<str.Length; i++)
{
arrData[DataLen++] = (byte)(str[i]&0x00ff);
if( (str[i]&0xff00) !=0 )
arrData[DataLen++] = (byte)( (str[i]&0xff00)>>8 );
}
m_DMEncode.nDataLength = DataLen ;*/
byte []arrData = new byte [str.Length ];
for( int i=0; i<str.Length; i++)
arrData[i] = (byte)(str[i]);
m_DMEncode.nDataLength = str.Length;
///////////////////////////////////////////
fixed(byte* p = arrData)
{
m_DMEncode.pData = p;
}
lRet = PtDMEncode( ref m_DMEncode, ref m_image );
if( lRet != PT_DMENCODE_SUCCESS)
{
MessageBox.Show ("Encode error!" );
return;
}
if( BarPicBox.Image != m_BlankImg )//clear BarPicBox
{
BarPicBox.Image = m_BlankImg;
m_BarcodeImg.Dispose();
}
lRet = PtSaveImage( "tempDMCode.bmp", ref m_image );
if(lRet != PT_IMAGERW_SUCCESS)
{
MessageBox.Show ("Save file error");
}
else
{
m_BarcodeImg = new Bitmap("tempDMCode.bmp");
BarPicBox.Image = m_BarcodeImg;
}
PtFreeImage(ref m_image);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -