为UIImageView生成BarCode

时间:2012-10-31 10:54:54

标签: iphone ios zxing zbar-sdk

我想在某些UIImage或UIImageView上生成条形码。 是否可能。我正在使用This生成条形码。

请帮帮我。 谢谢

3 个答案:

答案 0 :(得分:2)

另一种选择是使用在线条形码生成器的URL作为UIImage的源。例如:

NSString *barCodeValue = @"0123456789";
NSString *barCodeURL = [NSString stringWithFormat:@"http://www.barcodesinc.com/generator/image.php?code=%@&style=197&type=C128B&width=200&height=100&xres=1&font=3", barCodeValue];
barCodeImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:barCodeURL]]];

答案 1 :(得分:1)

我不确定,但你可以尝试一下:

1)将UIImage转换为Base64 String.

2)现在,您使用此字符串生成条形码。

[barcode setupQRCode:base64String];

希望它对你有所帮助......

答案 2 :(得分:0)

如果在UIView上生成BarCode组件,你可以截取这个视图的屏幕截图并从这个视图中获取图像希望这对你有所帮助

-(UIImage *)getFinalImageAndBarCodeView:(UIView*)view{
////Create a new render context of the UIView size, and set a scale so that the full stage will render to it.
UIGraphicsBeginImageContext(CGSizeMake(view.bounds.size.width, view.bounds.size.height));
CGContextScaleCTM(UIGraphicsGetCurrentContext(),1.0f,1.0f);

//Render the stage to the new context
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

// Get an image from the context
UIImage* viewImage=0;
viewImage=UIGraphicsGetImageFromCurrentImageContext();

// Kill the render context
UIGraphicsEndImageContext();

return viewImage;

}