如何从 QRCodeWriter 获取 Image.Source? [英] How do I get Image.Source from QRCodeWriter?
本文介绍了如何从 QRCodeWriter 获取 Image.Source?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对旧库有点挣扎,似乎无法从 QRCodeWriter 到 Image.Source 我可以放入我的图像中:D
I'm strugling a bit with old libs and can't seem to get from QRCodeWriter to a Image.Source I can put in my Image :D
我这样做:
QRCodeWriter writer = new QRCodeWriter();
var bMatrix = writer.encode("FOO FOO FOO", BarcodeFormat.QR_CODE, 300, 300);
但是从那以后我迷路了.bMatrix 有一个属性 Array
,但这是 zxings 的 ByteMatrix
类型,我仍然需要访问 Image.Source.
But from there on I'm lost. bMatrix has a property Array
, but this is of type zxings's ByteMatrix
and I still need to get to Image.Source.
WriteableBitmap
有 SetSource 和 SetValue,但我无法从 ByteMatrix
获取.:(
WriteableBitmap
has SetSource and SetValue but I can't wrap my head around getting from ByteMatrix
. :(
推荐答案
试试这个(从 pastebin 得到它:http://pastebin.com/612q0Qrb)
Try this (got it off of pastebin: http://pastebin.com/612q0Qrb)
QRCodeWriter writer = new QRCodeWriter();
com.google.zxing.common.ByteMatrix matrix;
int size = 180;
matrix = writer.encode("MECARD:N:Owen,Sean;ADR:76 9th Avenue, 4th Floor, New York, NY 10011;TEL:+12125551212;EMAIL:srowen@example.com;; ", BarcodeFormat.QR_CODE, size, size, null);
Bitmap img = new Bitmap(size, size);
Color Color = Color.FromArgb(0, 0, 0);
for (int y = 0; y < matrix.Height; ++y)
{
for (int x = 0; x < matrix.Width; ++x)
{
Color pixelColor = img.GetPixel(x, y);
//Find the colour of the dot
if (matrix.get_Renamed(x, y) == -1)
{
img.SetPixel(x, y, Color.White );
}
else
{
img.SetPixel(x, y, Color.Black);
}
}
}
img.Save(@"c:test.bmp",ImageFormat.Bmp);
这篇关于如何从 QRCodeWriter 获取 Image.Source?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文