New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code 128 generation #5

Open
bcharp opened this Issue Aug 25, 2011 · 11 comments

Comments

Projects
None yet
9 participants
@bcharp

bcharp commented Aug 25, 2011

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

This comment has been minimized.

Show comment
Hide comment
@netshade

netshade Aug 25, 2011

Owner

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.

Owner

netshade commented Aug 25, 2011

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

This comment has been minimized.

Show comment
Hide comment
@bcharp

bcharp Aug 25, 2011

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...

bcharp commented Aug 25, 2011

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

This comment has been minimized.

Show comment
Hide comment
@dalewking

dalewking Aug 25, 2011

Contributor

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:
#5

Dale King

Contributor

dalewking commented Aug 25, 2011

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:
#5

Dale King

@netshade

This comment has been minimized.

Show comment
Hide comment
@netshade

netshade Aug 25, 2011

Owner

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.

Owner

netshade commented Aug 25, 2011

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

This comment has been minimized.

Show comment
Hide comment
@bcharp

bcharp Aug 25, 2011

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...

bcharp commented Aug 25, 2011

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

This comment has been minimized.

Show comment
Hide comment
@doingforschool

doingforschool Jan 16, 2012

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!

doingforschool commented Jan 16, 2012

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

This comment has been minimized.

Show comment
Hide comment
@donnebrasko

donnebrasko Mar 16, 2012

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

Thank you

donnebrasko commented Mar 16, 2012

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

Thank you

@felixwcf

This comment has been minimized.

Show comment
Hide comment
@felixwcf

felixwcf Jan 8, 2013

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.

felixwcf commented Jan 8, 2013

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

This comment has been minimized.

Show comment
Hide comment
@pandora2000

pandora2000 Nov 25, 2013

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

pandora2000 commented Nov 25, 2013

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

This comment has been minimized.

Show comment
Hide comment
@yann86

yann86 Dec 31, 2013

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];

yann86 commented Dec 31, 2013

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

This comment has been minimized.

Show comment
Hide comment
@paleotek

paleotek Jan 16, 2014

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!

paleotek commented Jan 16, 2014

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment