1

我在使用旧库时有些挣扎,似乎无法从 QRCodeWriter 到 Image.Source 我可以放入我的 Image 中:D

我这样做:

QRCodeWriter writer = new QRCodeWriter();
var bMatrix = writer.encode("FOO FOO FOO", BarcodeFormat.QR_CODE, 300, 300);

但从那以后我迷路了。bMatrix 有一个属性Array,但这是 zxings 的类型ByteMatrix,我仍然需要访问 Image.Source。

WriteableBitmap有 SetSource 和 SetValue 但我无法从ByteMatrix. :(

4

1 回答 1

1

试试这个(从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);
于 2012-06-26T21:41:05.510 回答