jverkoey / ObjQREncoder

Objective-C QR Encoder
390 stars 101 forks source link

Issues with Encoding large strings and size/correction params #8

Open semephor opened 13 years ago

semephor commented 13 years ago

I am also finding the same issues as many other people when the strings for encoding becomes large... using the parameters of size/correction level does not solve the problem.

Firstly, using the default function:

Causes a memory problem for large strings as described by others. So then instead we need to call to other function:

... which allows you to put in size and correction level.

However, the library does not seem to work using the QR spec for how many chars you can code with qr version/correction level as specified here: http://www.denso-wave.com/qrcode/vertable1-e.html

So, no problem we can write our own function which can tell you what version number to go for for QR correction level LOW to avoid the memory exception:

+(int) genSize:(NSString *) myString; {

int version = 4;

if ([myString length] > 0 && [myString length] <19){
    version=2;
}

if ([myString length] >= 20 && [myString length] <33){
    version=2;
}

if ([myString length] >= 34 && [myString length] <54){
    version=3;
}

if ([myString length] >= 55 && [myString length] <79){
    version=4;
}

if ([myString length] > 80 && [myString length] <107){
    version=5;
}

if ([myString length] >= 108 && [myString length] <135){
    version=6;
}

if ([myString length] >= 136 && [myString length] <155){
    version=9;
}

if ([myString length] >= 156 && [myString length] <193){
    version=9;
}

return version;

}

Now there are no memory errors and you always get an image being output even for larger (100+ char) strings, however the image is often corrupt and not scannable by any QR decoder :(

Any help appretiated if I'm doing something wrong.

semephor commented 13 years ago

p.s. I can provide many images of QR codes this lib has generated which are not scannable if anyone is interested in helping solve this.