需要准备打印二维码的库:DataMatrix.net.dll
DataMatrix.net.dll下載地址:https://sourceforge.net/projects/datamatrixnet/files/rel0.4/rel0.4.4/
文字轉二維碼代碼實現如下:
private void button1_Click(object sender, EventArgs e)
{
try
{
string content = "1552458000";
Image image = Encode_DM(content, 2, 2);
pictureBox1.Image = image;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public Bitmap Encode_DM(string content, int moduleSize = 5, int margin = 5)
{
DmtxImageEncoderOptions opt = new DmtxImageEncoderOptions();
opt.ModuleSize = moduleSize;
opt.MarginSize = margin;//如果有显示不全的二维码,可以适当增大margin值
DmtxImageEncoder encoder = new DmtxImageEncoder();
Bitmap bm = encoder.EncodeImage(content, opt);
return bm;
}