Adil Hussain
Adil Hussain

Reputation: 32221

Encoded QR and Aztec barcodes contain blur/dither

I'm generating QR and Aztec barcodes in an iOS application using the latest version (3.2.1) of the ZXingObjC library. I'm doing so using code identical to the library's "Encoding" example, i.e:

NSError *error = nil;
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
ZXBitMatrix* result = [writer encode:@"A string to encode"
                              format:kBarcodeFormatQRCode
                               width:200
                              height:200
                               error:&error];

CGImageRef imageRef = [[ZXImage imageWithMatrix:result] cgimage];
UIImage *image = [UIImage imageWithCGImage:imageRef];
myImageView.image = image;

However, I see that the barcode which is rendered in my UIImageView using the above code contains some blur/dither when transitioning from a black block to a white block. This is undesirable and could impact scanning speed in an environment where scanning speed is top-priority. Here is an example of the barcode zoomed in to make the problem more apparent:

iOS barcode screenshot zoomed in

Question: Is there anything additional I can do when generating/rendering the barcodes in my iOS application to avoid this blur/dither??

Note that I have specified my UIImageView's Content Mode to be Center (UIViewContentModeCenter) so that it doesn't scale the contained image and thus I can't imagine the UIImageView causing the blur/dither.

As an aside: I'm using the equivalent com.google.zxing:core:3.3.0 library in an Android application and I'm not seeing the same problem there. See zoomed in screenshot of the barcode below from the Android application:

Android barcode screenshot zoomed in

Upvotes: 0

Views: 249

Answers (2)

Hrabovskyi Oleksandr
Hrabovskyi Oleksandr

Reputation: 3275

Got the same issue with the aztec code. After some research found out this could be fixed if set the magnificationFilter of the imageView layer to .nearest, you may check documentation about this filter.

Upvotes: 0

Adil Hussain
Adil Hussain

Reputation: 32221

After testing this on a couple of other devices (iPhone 5s and iPhone 7) I've come to the realisation that this is an issue specific to the iPhone 6+. Turns out that the "physical" resolution (1080 x 1920 px) of the iPhone 6+ is smaller than the "virtual" resolution (1242 x 2208 px) (see here) and thus the iPhone 6+ does some downsampling of the display and this is what is causing the blur/dither. Sadly I don't think there is anything that can be done about this... unless anyone has any suggestions??

Upvotes: 0

Related Questions