第一步,下载Google的ZXing类库,以便引用;

  BitMatrix bitMatrix;

        private void Button_Click_1(object sender, RoutedEventArgs e)
{
string content = this.txtChat.Text; Dictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, , );
this.img.Stretch = Stretch.Fill;
this.img.Source = toImage(bitMatrix);
}

下面代码是不同的转换

 private BitmapImage toImage(BitMatrix matrix)
{
try
{
int width = matrix.Width;
int height = matrix.Height; Bitmap bmp = new Bitmap(width, height); // byte[] pixel = new byte[width * height]; for (int x = ; x <height ; x++)
{
for (int y = ; y < width; y++)
{
if (bitMatrix[x, y])
{
bmp.SetPixel(x,y,System.Drawing.Color.Black);
}
else
{
bmp.SetPixel(x, y, System.Drawing.Color.White);
}
}
} return ConvertBitmapToBitmapImage(bmp);
}
catch (Exception ex)
{
throw ex;
} }
private static BitmapImage ConvertBitmapToBitmapImage(Bitmap wbm)
{
BitmapImage bimg = new BitmapImage(); using (MemoryStream stream = new MemoryStream())
{
wbm.Save(stream , System.Drawing.Imaging.ImageFormat.Png); bimg.BeginInit();
stream.Seek(, SeekOrigin.Begin);
bimg.StreamSource = stream;
bimg.CacheOption = BitmapCacheOption.OnLoad;
bimg.EndInit();
}
return bimg; }

希望对你有一点点帮助!

【WPF】生成二维码的更多相关文章

  1. WPF生成二维码

    WPF可以通过ZXing.Net库来实现二维码的功能. 可以通过NuGet安装: Install-Package ZXing.Net 二维码的实现代码: #region 二维码的方法 /// < ...

  2. 【C#/WPF】.Net生成二维码QRCode的工具

    先马 http://qrcodenet.codeplex.com/ 使用该工具WPF生成二维码的简单例子: 前台XAML准备一个Image控件显示二维码. string qrcodeStr = &qu ...

  3. C# WPF使用ZXing生成二维码ImageSource

    介绍: 如果需要实在WPF窗体程序中现类似如下的二维码图片生成功能,可以通过本文的方法实现 添加步骤: 1.在http://zxingnet.codeplex.com/站点上下载ZXing .Net的 ...

  4. C#利用QrCode.Net生成二维码(Qr码)

    在网上很多应用都是用二维码来分享网址或者其它的信息.尤其在移动领域,二维码更是有很大的应用场景.因为项目的需要,需要在网站中增加一个生成二维码分析网址的功能,在谷歌大幅度抽筋的情况下无奈使用百度.百度 ...

  5. C#利用QrCode.Net生成二维码(Qr码

    http://www.cnblogs.com/Soar1991/archive/2012/03/30/2426115.html 现在网上很多应用都是用二维码来分享网址或者其它的信息.尤其在移动领域,二 ...

  6. Javascript生成二维码(QR)

    网络上已经有非常多的二维码编码和解码工具和代码,很多都是服务器端的,也就是说需要一台服务器才能提供二维码的生成.本着对服务器性能的考虑,这种小事情都让服务器去做,感觉对不住服务器,尤其是对于大流量的网 ...

  7. 使用jquery.qrcode生成二维码(转)

    jQuery 的 qrcode 插件就可以在浏览器端生成二维码图片. 这个插件的使用非常简单: 1.首先在页面中加入jquery库文件和qrcode插件. <script type=" ...

  8. iOS 生成二维码

    首先先下载生成二维码的支持文件 libqrencode 添加依赖库 CoreGraphics.framework. QuartzCore.framework.AVFoundation.framewor ...

  9. QR code 扩展生成二维码

    include './phpqrcode/phpqrcode.php';  //引入QR库 QRcode::png("leo", 'qrcode.png', 'L', 10);  ...

  10. Python 创建本地服务器环境生成二维码

    一. 需求 公司要做一个H5手机端适配页面,因技术问题所以H5是外包的,每次前端给我们源码,我们把源码传到服务器让其他人访问看是否存在bug,这个不是很麻烦吗?有人说,可以让前端在他们的服务器上先托管 ...

随机推荐

  1. array_filter 过滤一维中空数组,数组的序列不变

    <?php header('Content-type:text;charset=utf8'); $str = "%11111%22222%333333%"; $arr = e ...

  2. 网站访问日志User Agent对照表

    percent useragent system user_agent_string_md5 8.9% Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleW ...

  3. 前端PHP入门-011-可变函数

    可变函数,我们也会称呼为变量函数.简单回顾一下之前的知识点: <?php $hello = 'world'; $world = '你好'; //输出的结果为:你好 echo $$hello; ? ...

  4. OpenCV---对象测量

    一:获取图像的外接矩形boundingRect和几何距moments import cv2 as cv import numpy as np def measure_object(image): gr ...

  5. [LeetCode] 28. Implement strStr() ☆

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  6. jdbc:oracle:thin:@localhost:1521:orcl和jdbc:oracle:thin:@localhost:1521/orcl的区别

      Oracle Thin JDBC Driver 驱动程序包名:ojdbc14.jar.ojdbc6.jar 驱动程序类名: oracle.jdbc.driver.OracleDriver JDBC ...

  7. hdu4699-Editor

    Sample Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Sample Output 2 3 发现IDLR四种操作都在光标处发生,且操作完成后光标至多移动1个位置,根据这种“ ...

  8. HDU 3507 单调队列 斜率优化

    斜率优化的模板题 给出n个数以及M,你可以将这些数划分成几个区间,每个区间的值是里面数的和的平方+M,问所有区间值总和最小是多少. 如果不考虑平方,那么我们显然可以使用队列维护单调性,优化DP的线性方 ...

  9. Python学习笔记(二十九)ThreadLocal

    import threading #创建全局ThreadLocal对象: local_school = threading.local() def process_student(): #获取当前线程 ...

  10. 开源中国愚人节网页变模糊的js blur代码

    <![if !IE]> <script> /* * by moli */ $(document).ready(function(){ if(document.cookie.in ...