mergZXing

mergZXing - iOS Barcode Reader External for LiveCode

mergZXing is a LiveCode external that uses ZXing library to read barcodes via the back camera of a mobile device. Because of the need for the external to use the back camera of the device it does not function in the simulator. The external supports iOS 4 and up and devices with an autofocus camera (iPhone 3GS and up). Devices without autofocus may scan under certain conditions with better performance on 2D codes (QR, DataMatrix).

mergZXing contains ZXing 1.7 (pronounced "zebra crossing") which is an open-source, multi-format 1D/2D barcode image processing library.

Copyright 2008 ZXing authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For more information about complying with this license please refer to the License Questions page on the ZXing wiki.

mergZXing currently supports reading barcodes in these formats:

  • UPC-A and UPC-E
  • EAN-8 and EAN-13
  • Code 39
  • Code 128
  • QR Code
  • ITF
  • Data Matrix

mergZXing Syntax

function mergZXingGetBarcode()

Syntax example: put mergZXingGetBarcode() into tBarcode

Presents a modal barcode reader and returns when a barcode is read or the user cancels.

Returns:

  • The read barcode
  • If the user touches up on the cancel button the function will return "mergBarcode: user cancelled"
  • If there is a barcode reader control already on screen then the function will return "mergZXing:Error: control already created"

function mergZXingDecodeImage(pImagePath)

Syntax example:

on mouseUp
  if there is an image 1 then delete image 1
  set the visible of the templateImage to false
  mobilePickPhoto "camera",480,360
  if the result = "cancel" then
    exit mouseUp
  end if
  put specialFolderPath("temporary") &"/image.jpg" into tPath
  export image 1 to file tPath as JPEG
  put mergZXingDecodeImage(tPath) into fld 1
end mouseUp

Scans the supplied image for a barcode.

Returns:

  • The read barcode
  • If there is a barcode reader control already on screen then the function will return "mergZXing:Error: control already created"
  • If a barcode couldn't be found "mergZXing: failed to decode image"

command mergZXingControlCreate pLeft,pTop,pRight,pBottom

Syntax example:

mergZXingControlCreate 0,0,the width of this stack,the height of this stack div 2

Displays a barcode reader control in the rect specified.

Results:

  • If successful then the result is set to mergZXing: control created
  • If there is a barcode reader control already on screen then the result is set to "mergZXing:Error: control already created"

command mergZXingControlSetRect pLeft,pTop,pRight,pBottom

Syntax example:

mergZXingControlSetRect 0,0,the width of this stack,the height of this stack div 2

Alters the rect of an existing barcode reader control.

Results:

  • If successful then the result is set to "mergZXing: control rect set"
  • If there is not a barcode reader control already on screen then the result is set to "mergZXing:Error: control not created yet"

command mergZXingControlDelete

Syntax example:

mergZXingControlDelete

Removes an existing barcode reader control from screen.

Results:

  • If successful then the result is set to "mergZXing: control deleted"
  • If there is not a barcode reader control already on screen then the result is set to "mergZXing:Error: control not created yet"

message mergZXingDidScanResult pBarcode,pImage

Syntax example:

on mergZXingDidScanResult pBarcode,pImage
  answer pBarcode
  put pImage into image "scanned barcode"
end mergZXingDidScanResult

Sent to the default card when a barcode is scanned using the mergZXing control.

Parameters

  • pBarcode - the scanned barcode text
  • pImage - the png data of the scanned barcode

Puting it all together

on preOpenCard
  if the environment = "mobile" then
    mergZXingControlCreate 0,the bottom of grc "rectangle",the width of this stack,the height of this stack div 2
  end if
  pass preOpenCard
end preOpenCard
 
on closeCard
  if the environment = "mobile" then
    mergZXingControlDelete
  end if
  pass closeCard
end closeCard
 
on mergZXingDidScanResult pBarcode
  beep 1
  put pBarcode&cr before fld "results"
end mergZXingDidScanResult