How to create a barcode image in ios

I use the following code to create a barcode and display the barcode in the current view

OBLinear *pLinear = [OBLinear new]; [pLinear setNBarcodeType: OB_CODE128A]; [pLinear setPDataMsg: [[NSString alloc] initWithString: (@"SUKUMAR")]]; //[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:view]; 

This works fine, however I need to create a barcode without showing it in the view.

How can I generate barcode images without displaying it in a view. If anyone knows how to do this, please help me.

Thanks in advance...

+4
source share
2 answers

I assume this is the interface of the class you are using: OBLinear.h

If so, it looks like you can generate a UIImage just by doing this:

 UIImage *image; [plLinear drawWithImage:&image]; 

Then you can do whatever you want with image . For example, you can convert it to PNG using UIImagePNGRepresentation and upload the PNG data to your server or save it to a file.

+3
source

You are probably looking for something like this SO question:

Capturing UIView as a UIImage

+1
source

All Articles