网上能找到的参考资料不多,其实很简单本人分享下吧:
1.引用ZXing库百度一下,不同版本的ZXing库架构略有不同。部分方法和属性的调用会有些少出入,本文使用的是最新的 zxing.wp8.0.dll。
2.引用
using ZXing;
using ZXing.OneD;
using ZXing.Common;
3.直接贴出我项目里写好的通用:
/// <summary>
/// 生成可直接使用的位图对象
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static WriteableBitmap CreateBarcode(string str)
{
WriteableBitmap wb = null;
Code128Writer writer = new Code128Writer();
BitMatrix bitMatrix;
try
{
bitMatrix = writer.encode(str, BarcodeFormat.CODE_128, 440, 120);
wb = ConvertByteMartixToWriteableBitmap(bitMatrix);
}
catch
{
}
return wb;
}
/// <summary>
/// 将点矩阵转化为位图
/// </summary>
/// <param name="bm"></param>
/// <returns></returns>
public static WriteableBitmap ConvertByteMartixToWriteableBitmap(BitMatrix bm)
{
WriteableBitmap wb = new WriteableBitmap(bm.Width, bm.Height);
for (int x = 0; x <= wb.PixelWidth - 1; x++)
{
for (int y = 0; y <= wb.PixelHeight - 1; y++)
{
if (!bm[x, y])
{
//白色
wb.Pixels[wb.PixelWidth * y + x] = BitConverter.ToInt32(BitConverter.GetBytes(0xffffffff), 0);
}
else
{
//黑色
wb.Pixels[wb.PixelWidth * y + x] = BitConverter.ToInt32(BitConverter.GetBytes(0xff000000), 0);
}
}
}
return wb;
}
基本直接调用就行了,懂的不用问,不懂的自己问自己