PCB Genesis加二维码 实现方式
使用incam可以很轻松的增加2维码,这里通过另外一种方式玩转二维码的加法,
使用谷歌zxing.dll类库实现,将文字信息转为bitmap点阵后,在Genesis绘制点即可。
一.incam增加二维码效果

二.通过代码增加方PAD实现效果:

三.代码实现:
Genesis增加二维码代码
private void addQR()
{
CodeHelper qr = new CodeHelper();
Dictionary<EncodeHintType, object> hint = new Dictionary<EncodeHintType, object>();
hint.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//设置内容编码
hint.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);//错码率 L水平 7 % M水平 15 % Q水平 25 % H水平 30 %
hint.Add(EncodeHintType.QR_VERSION, );//大小 (V-1)*4 + 21(V是版本号)
hint.Add(EncodeHintType.MARGIN, );//边距
ZXing.Common.BitMatrix codeArray = qr.enMatrix("at00101ca0", , , BarcodeFormat.QR_CODE, hint); //at00101ca0为增加二维码内容
add add_ = new add();
gPP gp = new gPP();
gp.width = ;//PAD大小
gp.symbols = "s";//PAD形状为方PAD
for (int x = ; x < codeArray.Width; x++)
{
for (int y = ; y < codeArray.Height; y++)
{
if (codeArray[x, y])
{
gp.p.x = x * 0.5;
gp.p.y = y * 0.5;
add_.pad(gp); //增加方PAD PAD
}
}
}
}
zxing.dll重新封装后的二维码类
public class CodeHelper
{ public string CHARSET = "UTF-8"; public static int SaveTo(Bitmap bitmap, string filepath, string filename)
{
try
{
bitmap.Save(filepath + filename); return ;
}
catch (System.Exception ex)
{
return -;
}
}
/// <summary>
///字符转二维码
/// </summary>
/// <param name="content"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="barcodeFormat"></param>
/// <param name="hints"></param>
/// <returns></returns>
public Bitmap encode(string content, int width, int height, BarcodeFormat barcodeFormat, IDictionary<EncodeHintType, object> hints)
{
BitMatrix byteMatrix = new MultiFormatWriter().encode(content, barcodeFormat, width, height, hints);
Bitmap bitmap = toBitmap(byteMatrix);
return bitmap;
} /// <summary>
///字符转二维码
/// </summary>
/// <param name="content"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="barcodeFormat"></param>
/// <param name="hints"></param>
/// <returns></returns>
public string enString(string content, int width, int height, BarcodeFormat barcodeFormat, IDictionary<EncodeHintType, object> hints)
{
BitMatrix byteMatrix = new MultiFormatWriter().encode(content, barcodeFormat, width, height, hints);
return toString(byteMatrix);
}
/// <summary>
///字符转二维码
/// </summary>
/// <param name="content"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="barcodeFormat"></param>
/// <param name="hints"></param>
/// <returns></returns>
public BitMatrix enMatrix(string content, int width, int height, BarcodeFormat barcodeFormat, IDictionary<EncodeHintType, object> hints)
{
BitMatrix byteMatrix = new MultiFormatWriter().encode(content, barcodeFormat, width, height, hints);
return byteMatrix;
}
/// <summary>
/// 字符转二维码
/// </summary>
/// <param name="content"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="barcodeFormat"></param>
/// <returns></returns>
public Bitmap encode(string content, int width, int height, BarcodeFormat barcodeFormat)
{
BitMatrix byteMatrix = new MultiFormatWriter().encode(content, barcodeFormat, width, height); Bitmap bitmap = toBitmap(byteMatrix);
return bitmap;
}
/// <summary>
/// BitMatrix转Bitmap
/// </summary>
/// <param name="matrix"></param>
/// <returns></returns>
private static String toString(BitMatrix matrix)
{
StringBuilder bitString = new StringBuilder(); for (int x = ; x < matrix.Width; x++)
{
bitString.Append("\r\n");
for (int y = ; y < matrix.Height; y++)
{
//bitmap.SetPixel(x, y, matrix[x, y] ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
bitString.Append(matrix[x, y] ? "■" : " ");
}
}
return bitString.ToString ();
}
/// <summary>
/// BitMatrix转Bitmap
/// </summary>
/// <param name="matrix"></param>
/// <returns></returns>
private static Bitmap toBitmap(BitMatrix matrix)
{
int width = matrix.Width;
int height = matrix.Height;
Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int x = ; x < width; x++)
{
for (int y = ; y < height; y++)
{
bitmap.SetPixel(x, y, matrix[x, y] ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
}
}
return bitmap;
} /// <summary>
/// 字符转二维码并保存
/// </summary>
/// <param name="content"></param>
/// <param name="path"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="barcodeFormat"></param>
/// <returns></returns>
public int encodeAndSave(string content, string path, int width, int height, BarcodeFormat barcodeFormat)
{
return SaveTo(encode(content, width, height, barcodeFormat), path, "");
}
/// <summary>
/// bmp图片路径转换??
/// </summary>
/// <param name="bmppath"></param>
/// <param name="hints"></param>
/// <param name="result"></param>
/// <returns></returns>
public static int decode(string bmppath, IDictionary<DecodeHintType, object> hints, out Result result)
{
Bitmap bmap = new Bitmap(bmppath);
BitmapLuminanceSource source = new BitmapLuminanceSource(bmap);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = new MultiFormatReader().decode(bitmap, hints);
return ;
}
}
PCB Genesis加二维码 实现方式的更多相关文章
- php生成二维码的几种方式整理及使用实例
hp生成二维码的方式:1.google开放api:2.php类库PHP QR Code:3.libqrencode:4.QRcode Perl CGI & PHP scripts感兴趣的朋友可 ...
- php生成二维码的几种方式
一些php生成二维码的方式:1.google开放api:2.php类库PHP QR Code:3.libqrencode:4.QRcode Perl CGI & PHP scripts 1.g ...
- 使用jquery.qrcode生成二维码实现微信分享功能
前言: 最近有个这样的需求,在pc端的商品详情页增加分享功能. 微博分享.QQ好友分享.QQ空间分享这些都很常见.但是微信分享我还没有手动写过(以前改过). 最终效果如下图: 解决方案:使用jquer ...
- 二维码相关---java生成二维码名片,而且自己主动保存到手机通讯录中...
版权声明:本文为博主原创文章,未经博主credreamer 同意不得转载 违者追究法律责任. https://blog.csdn.net/lidew521/article/details/244418 ...
- Java 获取微信小程序二维码(可以指定小程序页面 与 动态参数)
一.准备工作 微信公众平台接口调试工具 小程序的唯一标识(appid) 小程序的密钥(secret) 二.获取access_token 打开微信公众平台接口调试工具,在参数列表中输入小程序的appid ...
- Java语言实现二维码的生成
众所周知,现在生活中二维码已经是无处不见.走在街道上,随处可见广告标语旁有二维码,手机上QQ,微信加个好友都能通过二维码的方式,我不知道是什么时候兴起的二维码浪潮,但是我知道,这在我小时候可是见不到的 ...
- [C#]二维码(QR Code)生成与解析
写在前面 经常在大街上听到扫码送什么什么,如果真闲着没事,从头扫到位,估计书包都装满了各种东西.各种扫各种送,太泛滥了.项目中从没接触过二维码的东东,最近要使用,就扒了扒网络,发现关于解析二维码的类库 ...
- 二维码(QR Code)生成与解析
二维码(QR Code)生成与解析 写在前面 经常在大街上听到扫码送什么什么,如果真闲着没事,从头扫到位,估计书包都装满了各种东西.各种扫各种送,太泛滥了.项目中从没接触过二维码的东东,最近要使用,就 ...
- java生成二维码(带logo)
之前写过一篇不带logo的二维码实现方式,採用QRCode和ZXing两种方式 http://blog.csdn.net/xiaokui_wingfly/article/details/3947618 ...
随机推荐
- Spring学习笔记_day01_ioc
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! Spring_day01 spring是一站式的框架, ...
- C# 控件调整
//最大化 this.WindowState = FormWindowState.Maximized; //去掉标题栏 this.FormBorderStyle = FormBorderStyle.N ...
- Shell基本运算符
原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用. expr 是一款表达式计算工具,使用它能完成表达式的求值操作. 例如,两个数相加(注意使用 ...
- AcDbTable 类
Table 例子学习笔记在这个例子中,ARX向我们展示了ACDBTABLE类的一些基本操作方法,ACDBTABLE类是ACAD2005及其以后的产品,应该是说ACDBDATATABLE的升级产品,Ac ...
- IE浏览器new Date()带参返回NaN解决方法
var start = '2016-01-01 12:12:12'; var date = new Date(start); 得到的时间为NaN: 解决方法: 1.自定义方法 自定义一个NewDate ...
- EAS之校验检查
先了解一下权限接口类提供的有关权限项检查的方法public boolean hasFunctionPermission(IObjectPK userPK,IObjectPK orgPK,String ...
- php第二十一节课
AJAX <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- 找零钱的算法实现(Java)
简单的算法 基本思路就是将面值从大到小统计(外循环), 若当前金额大于某面值, 则当前金额减掉该面值, 并将面值对应张数+1, 继续往下判断(内循环) public void Change(int m ...
- Git 基础教程 之 远程推送
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应了起来,并且,远程仓库默认名称是origin. git remote 查看远程库信息 git remote - ...
- CodeForcesGym 100735B Retrospective Sequence
Retrospective Sequence Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on C ...