Generate 2D bar code (e.g. QR Code, Data Matrix, P

2019-04-10 13:45发布

问题:

I need a library to generate a 2D bar code on iPhone and Android (and preferably WM7 and possibly j2me too) - the idea is to transfer information to another device with a corresponding scanner (decoder). What are the good options?

ZXing is an option, in particular for the reading/decoding aspect, but I want to generate them on these devices.

回答1:

zxing will work for Android. The Java encoder hasn't been ported to C++ (feel free to jump in and contribute ... shouldn't be that hard.) Until that happens, I've been using the psytec encoder (http://groups.google.com/group/zxing/msg/27e421daeb510d0f). The comments are in Japanese, but it's pretty straightforward.

I don't have anything to add on WM7. Is that C#? There is a C# port of zxing but I don't know of anyone actively maintaining it and don't know if it includes an encoder.



回答2:

Best option should be ZXing's library. I'm not sure about the Windows Phone 7 support tho.



回答3:

I tried all solutions described above with no success, but then found this library: akopanev-iOS-QR-Code-Encoder

Open-source, simple to implement, has sample xcode project, works great

author - Andrew Kopanev



回答4:

I have been using ZXING to encode QR barcodes successfully. However, at least with the current version, it appears to have limited support for encoding other symbologies (ex: PDF-417).

I use the following code snippet:

    // Encode the bitmap and display it on the screen
    try {
        // This will produce a 150x150 QR Barcode and display it on the screen.
        Bitmap bm = encodeAsBitmap(barcodeContentString, BarcodeFormat.QR_CODE, 150, 150);

        if(bm != null) {
            barcodeImage.setImageBitmap(bm);
        }
}
    catch (WriterException e) { ... }

In this example, the "barcodeContentString" is the data that is being encoded. The "barcodeImage" is a standard ImageView.

I don't show it here, but I turn the screen on for the entire length of time that the barcode is displayed. As such, I am able to successfully scan the barcode with a QR compatible barcode scanner.



回答5:

If you are going to transfer to another device online, then you might want to use a 3rd party QR code API to get the image. Making a call to an REST API is the best option of cross-platform mobile apps.

This API does it for URI's: http://www.tag.cx/qr-codes/

You could also host your own private QR code generator API.



回答6:

Here is another Java version: http://qrcode.sourceforge.jp/

Summary--"This project develops and distributes QR Code decode/encode library under GPL v2. The project goal is Utilize QR Code embedded information for programmable devices all over the world. QR Code is the industrial standard, JIS-X-0510 and ISO/IEC18004."



回答7:

Also check out (I couldn't post these because stackoverflow prevented more than one url): And a .net version (as listed on the site above): http://www.codeproject.com/KB/cs/qrcode.aspx



回答8:

Also check out (I couldn't post these because stackoverflow prevented more than one url): A python version (as listed on the site above): http://pyqrcode.sourceforge.net/



回答9:

I might be too late to help you in any way, but I have found a good SDK for Data Matrix codes. More instructions are on their website HERE, but to provide the code here as well, you'd do something like this:

OBLinear *pLinear = [OBLinear new];
[pLinear setNBarcodeType: OB_CODE128A];
[pLinear setPDataMsg: [[NSString alloc] initWithString:@"AB"]];
//[pLinear setPSupData: [[NSString alloc] initWithString:@"14562"]];
[pLinear setFX: USER_DEF_BAR_WIDTH];
[pLinear setFY: USER_DEF_BAR_HEIGHT];

[pLinear setFLeftMargin:USER_DEF_LEFT_MARGIN];
[pLinear setFRightMargin:USER_DEF_RIGHT_MARGIN];
[pLinear setFTopMargin:USER_DEF_TOP_MARGIN];
[pLinear setFBottomMargin:USER_DEF_BOTTOM_MARGIN];

[pLinear setNRotate:OB_Rotate0];

UIFont *pTextFont = [UIFont fontWithName: @"Arial" size: 8.0f];
[pLinear setPTextFont: pTextFont];

[pLinear drawWithView:self.view];