iOS Question How to Generate 1D-Barcode

lkching7

Member
Licensed User
Longtime User
Look Through The Forum. I Found How to Generate QRCode, But I Cannot Find How to Generate the 1D Barcode, eg. Code39, Code128.

Any One Can Share The Solution ? Many Thank !
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tomorrow came early:
B4X:
Sub CreateCode128Barcode (Text As String) As B4XBitmap
   Dim filter As NativeObject
   filter = filter.Initialize("CIFilter").RunMethod("filterWithName:", Array("CICode128BarcodeGenerator"))
   filter.RunMethod("setDefaults", Null)
   filter.SetField("inputMessage", filter.ArrayToNSData(Text.GetBytes("UTF8")))
   Dim no As NativeObject = Me
   Return no.RunMethod("convertToUIImage:", Array(filter.GetField("outputImage")))
End Sub

#if OBJC
- (UIImage*) convertToUIImage:(CIImage*)img {
   return [[UIImage alloc]initWithCIImage:[img imageByApplyingTransform:CGAffineTransformMakeScale(5.0, 5.0)]];
}
#End If

(tested on iOS 13, probably supported by iOS 10+)
 
Upvote 0

lkching7

Member
Licensed User
Longtime User

It Work ! Thank Erel

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…