netshade / Cocoa-Touch-Barcodes

Fork of Jeff Lamarche's original barcode generator library at http://code.google.com/p/cocoabarcodes/
285 stars 63 forks source link

code 128 generation #5

Open bcharp opened 13 years ago

bcharp commented 13 years ago

Hi,

I'm trying to generate code 128 A or B barcode with 7 digit like 3144798 (not a code 128C because I need to have 7 digit not 8) and I'm becoming a bit crazy, it seems that the generated barcode isn't right... It ALMOST look like a barcode I can generate somewhere like here : http://generator.onbarcode.com/online-code-128-barcode-generator.aspx But when I look closely some bars aren't right and my linea pro won't scan the barcode(after printing not on the screen).

Here is the code I use to generate the barcode, maybe I'm doing something wrong.

NKDCode128Barcode barcode = [NKDCode128Barcode alloc]; barcode = [barcode initWithContent:@"3144798" printsCaption:NO]; [barcode setBarWidth:1.0]; [barcode setCodeSet:SET_B]; NSLog(@"%@",[barcode description]); UIImage theImage = [UIImage imageFromBarcode:barcode inRect:CGRectMake(0.0, 0.0, 300, 100.0)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:theImage]; imageView.contentMode = UIViewContentModeCenter; imageView.frame = CGRectMake(10.0, 100.0, 300, 100); [self.view addSubview:imageView];

I switched on code 39 for the time being, it seems to works great, but code 128 would be better... In any case thank you all for the amazing works.

netshade commented 13 years ago

Can you try generating the barcode as a PDF and drawing it to the screen in your drawRect with CGContextDrawPDFPage? I ask because I had better success with barcode scanning when generating the barcode as a PDF and drawing it to the screen than I did using a UIImage generated from the CGContext draw calls. I didn't get around to investigating the "why's" closely enough to give you an absolute reason why this works, but my theory at the time of working w/ it was that there was some aliasing occurring in the UIImage draw that wasn't happening when I drew a CGPDFDocumentRef to the screen.

Sorry can't be more exact, but hope that helps.

bcharp commented 13 years ago

Thanks for the quick answer and the tips !!! I tried but.... no more success...(it seems more precise thought)

In fact here is the code 128 that I generate with cocoa touch http://dl.dropbox.com/u/3037130/ios%20generated%20code%20128a.png

And there is another one generated on some website : http://dl.dropbox.com/u/3037130/some%20site%20generated%20code128a.png

The begining is the same but between the middle and the last 3 bar there is some differences.. I don't know if you can try a guess...

dalewking commented 13 years ago

Note CocoaTouchBarcodes is not my library. It is simply a library that we used on a previous project that was not on github and we needed to make changes to. I do not maintain CocoaTouchBarcodes and the project we used it for is now dead so I am not the right person to talk to.

If you need changes on github feel free to fork it. I and Chris Z. (aka netshade, the guy that actually pulled it onto github) will not be making and changes or providing support.

For support and thanking people go to http://code.google.com/p/cocoabarcodes/ which is the real home of the project.

On Thu, Aug 25, 2011 at 9:10 AM, bcharp < reply@reply.github.com>wrote:

Hi,

I'm trying to generate code 128 A or B barcode with 7 digit like 3144798 (not a code 128C because I need to have 7 digit not 8) and I'm becoming a bit crazy, it seems that the generated barcode isn't right... It ALMOST look like a barcode I can generate somewhere like here : http://generator.onbarcode.com/online-code-128-barcode-generator.aspx But when I look closely some bars aren't right and my linea pro won't scan the barcode(after printing not on the screen).

Here is the code I use to generate the barcode, maybe I'm doing something wrong.

NKDCode128Barcode barcode = [NKDCode128Barcode alloc]; barcode = [barcode initWithContent:@"3144798" printsCaption:NO]; [barcode setBarWidth:1.0]; [barcode setCodeSet:SET_B]; NSLog(@"%@",[barcode description]); UIImage theImage = [UIImage imageFromBarcode:barcode inRect:CGRectMake(0.0, 0.0, 300, 100.0)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:theImage]; imageView.contentMode = UIViewContentModeCenter; imageView.frame = CGRectMake(10.0, 100.0, 300, 100); [self.view addSubview:imageView];

I switched on code 39 for the time being, it seems to works great, but code 128 would be better... In any case thank you all for the amazing works.

Reply to this email directly or view it on GitHub: https://github.com/netshade/Cocoa-Touch-Barcodes/issues/5

Dale King

netshade commented 13 years ago

bcharp: Weird. The code 128 algorithm has always been a bit flaky, both dale and I had to make some bugfixes to it. If you have time to take a look at it, it'd be appreciated; otherwise, when I can get to it, I'll try, but I'm not actively maintaining this atm.

bcharp commented 13 years ago

Ok guys, thanks anyway. I will just use code 39 for now. If I got some times I will try to understand why code 128 return odd stuff...

doingforschool commented 12 years ago

Hi!

I am doing a project which can auto generated a barcode through my iphone application. I happened to find this https://github.com/netshade/Cocoa-Touch-Barcodes which i think would be a great help to me. However, nothing happened when i use it. These are the steps i have done:

1) Open my own iphone application and import all the .h and .m files. 2) After which, i type this into my barcode.m (this is the xib showing the auto generated barcode)

import "UIImage-NKDBarcode.h"

import "NKDCode39Barcode.h"

-(void)showBarcode { NKDBarcode * nkdbarcode = [[NKDCode39Barcode alloc] initWithContent:@"1234567890123"]; UIImage * image = [UIImage imageFromBarcode:nkdbarcode]; // assume barcodeIV is an outlet to an imageview [barcodeIV setImage:image]; }

But it did not work. Did i miss anything or did something wrong? Sincerely hope that anyone can help me out :)

Thanks&Regards!

donnebrasko commented 12 years ago

Hello, is someone find a way to generate barcode 128 ?

Thank you

felixwcf commented 11 years ago

I have a generated 128-bit barcode which the last 3 bar is cut off. The barcode number is 0395400000000236. I checked by using few barcode generator on website and problem is defined.

pandora2000 commented 10 years ago

Hi, I don't know what I experienced is helpful, but some barcode generated by this library cannot be read by some reader. And I think we must specify bar width ( but I don't read code carefully enough ). I added new constructor and if you specify imageWidth, it calculate appropriate barWidth. https://github.com/pandora2000/Cocoa-Touch-Barcodes

yann86 commented 10 years ago

Hi, if you change the codeSet after the method : -(id)initWithContent: (NSString *)inContent printsCaption: (BOOL)inPrints

you should call the generateChecksum method for recalculating the checkDigit.

NKDCode128Barcode *barcode = [NKDCode128Barcode alloc]; barcode = [barcode initWithContent:@"3144798" printsCaption:NO]; [barcode setBarWidth:1.0]; [barcode setCodeSet:SET_B]; [barcode generateChecksum];

paleotek commented 10 years ago

I had issues with this until I figured out that to match my requirements, I needed to generate the barcode without a checksum, then add the checksum explicitly. Not having a checksum will trim a few lines off your barcode, which might be what felixwcf and pandora2000 were seeing. Taking yann86's tip (thanks!), this worked for me:

    NKDCode128Barcode *otherBarcode = [[NKDCode128Barcode alloc] initWithContent:@"SURG"       
        printsCaption:NO andBarWidth:1.0 andHeight:15 andFontSize:7 andCheckDigit:-1];
    [otherBarcode setCodeSet:SET_B];
    [otherBarcode generateChecksum];
    image = [UIImage imageFromBarcode:otherBarcode];

The value of -1 for andCheckDigit on the first line means "no check digit". Then I add the check digit in the third line. Good luck!