DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • How to Create a Successful API Ecosystem
  • MCP Servers: The Technical Debt That Is Coming

Trending

  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 1
  • A Complete Guide to Modern AI Developer Tools
  • Building Resilient Networks: Limiting the Risk and Scope of Cyber Attacks
  1. DZone
  2. Data Engineering
  3. Databases
  4. What's New in HMS Core Scan Kit 6.11.0

What's New in HMS Core Scan Kit 6.11.0

HMS Core Scan Kit just debuted its new version. Read on to see what this version offers and how it helps with improving barcode scanning functions.

By 
Jackson Jiang user avatar
Jackson Jiang
DZone Core CORE ·
Jun. 30, 23 · News
Likes (1)
Comment
Save
Tweet
Share
3.2K Views

Join the DZone community and get the full member experience.

Join For Free

The latest version (6.11.0) of HMS Core Scan Kit is now available, and this article aims to share some of its exciting new features with you:

  • The kit adds the decode API that is available to both camera-based and image-based barcode scanning scenarios.

This API supports image data in NV21 format (which is output by your custom camera API) and multi-barcode recognition. Compared with decodeWithBitmap, an API released in an earlier version that supports only the bitmap format, the decode API saves time converting the image format and delivers a faster barcode scanning process in the camera-based mode.

  • The kit supports the multi-functional code.

This is a printed physical tag. To pair a phone with a device that has such a code, a user can simply use the phone to scan the code, tap the phone against the code, or get the phone close to the code.

Below is an example of such a code.

Example code

Now let's check how to use the new decode API in different barcode scanning scenarios.

Scanning a Barcode in Camera-Based Mode

1. Obtain an image frame of the camera.

Java
 
"Java"
// Convert the data array of the camera into a ByteArrayOutputStream stream. data is an instance of the byte array, and camera is an instance of android.hardware.Camera. 
YuvImage yuv = new YuvImage(data, ImageFormat.NV21, camera.getParameters().getPreviewSize().width, 
        camera.getParameters().getPreviewSize().height, null);

"Kotlin"
// Convert the data array of the camera into a ByteArrayOutputStream stream. data is an instance of the byte array, and camera is an instance of android.hardware.Camera. 
val yuv = YuvImage(data, ImageFormat.NV21, camera.getParameters().getPreviewSize().width, 
        camera.getParameters().getPreviewSize().height, null)


2. Convert the obtained YUV data streams to HmsScanFrame.

Java
 
"Java"
HmsScanFrame frame= new HmsScanFrame(yuv);

"Kotlin"
val frame = HmsScanFrame(yuv)


3. Initialize HmsScanFrameOptions to set the supported barcode formats and set whether to use the camera-based mode or image-based mode for barcode scanning, whether to recognize a single barcode or multiple barcodes, and whether to enable barcode parsing:

  • setHmsScanTypes(int type): sets the supported barcode formats. Fewer formats mean faster scanning. All formats supported will be scanned by default.
  • setPhotoMode(boolean photoMode): sets whether to use the camera-based mode or image-based mode for barcode scanning. The default value is false (camera-based mode).
  • setMultiMode(boolean multiMode): sets whether to recognize a single barcode or multiple barcodes. The default value is false (single barcode).
  • setParseResult(boolean parseResul): sets whether to enable barcode parsing. Set the parameter to false if you only need the original scanning result. In this case, the format of the recognized barcode will be returned in text via getScanType(). The default value is true (barcode parsing is enabled).
Java
 
"Java"
// QRCODE_SCAN_TYPE and PDF417_SCAN_TYPE indicate that only barcodes in the QR code format and PDF-417 format are supported. 
HmsScanFrameOptions option = new HmsScanFrameOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE| HmsScan.PDF417_SCAN_TYPE).setMultiMode(false).setParseResult(true).setPhotoMode(true).create();

"Kotlin"
// QRCODE_SCAN_TYPE and PDF417_SCAN_TYPE indicate that only barcodes in the QR code format and PDF-417 format are supported. 
HmsScanFrameOptions option = new HmsScanFrameOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE| HmsScan.PDF417_SCAN_TYPE).setMultiMode(false).setParseResult(true).setPhotoMode(true).create()


4. Call decode (a static method) of ScanUtil to initiate a barcode scanning request and obtain the scanning result object HmsScanResult. For the information contained in this object, please refer to Parsing Barcodes.

  • If you do not have specific requirements on barcode formats, set options to null.
  • If the barcode detected is too small, Scan Kit will return an instruction to the app for adjusting the camera's focal length to obtain a clearer barcode image.
Java
 
"Java"
HmsScanResult result = ScanUtil.decode(BitmapActivity.this, frame, option); 
HmsScan[] hmsScans = result.getHmsScans(); 
// Process the parsing result when the scanning is successful. 
if (hmsScans != null && hmsScans.length > 0 && !TextUtils.isEmpty(hmsScans[0].getOriginalValue())) { 
    // Display the scanning result. 
    ... 
} 
// If the value of zoomValue is greater than 1.0, adjust the focal length by using getZoomValue() and scan the barcode again. 
if (hmsScans != null && hmsScans.length > 0 && TextUtils.isEmpty(hmsScans[0].getOriginalValue()) && hmsScans[0].getZoomValue() != 1.0) { 
    // Set the focal length of the camera. The camera generates new bitmap data and scans again. (The convertZoomInt() function converts the magnification level to the focal length parameter that can be received and recognized by the camera.) 
    Camera.Parameters parameters= camera.getParameters(); 
    parameters.setZoom(convertZoomInt(hmsScans[0].getZoomValue())); 
    camera.setParameters(parameters); 
}

"Kotlin"
val hmsScansResult= ScanUtil.decode(this@BitmapActivity, frame, options) 
val hmsScans = hmsScansResult.hmsScans 
// Process the parsing result when the scanning is successful. 
if (hmsScans != null && hmsScans.size > 0 && !TextUtils.isEmpty(hmsScans[0].getOriginalValue())) { 
    // Display the scanning result. 
    ... 
} 
// If the value of zoomValue is greater than 1.0, adjust the focal length by using getZoomValue() and scan the barcode again. 
if (hmsScans != null && hmsScans.size > 0 && TextUtils.isEmpty(hmsScans[0].getOriginalValue()) && hmsScans[0].getZoomValue() != 1.0) { 
    // Set the focal length of the camera. The camera generates new bitmap data and scans again. (The convertZoomInt() function converts the magnification level to the focal length parameter that can be received and recognized by the camera.) 
    var parameters= camera.getParameters() 
    parameters.setZoom(convertZoomInt(hmsScans[0].getZoomValue())) 
    camera.setParameters(parameters) 
}


Scanning a Barcode in Image-Based Mode

1. Obtain an image and convert it into bitmap data.

Java
 
"Java"
// data is of the Intent type, and data.getData is the URI of the barcode image to be scanned. 
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());

"Kotlin"
// data is of the Intent type, and data.getData is the URI of the barcode image to be scanned. 
val bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData())


2. Initialize HmsScanFrameOptions, set your desired barcode formats, and set the Bitmap mode to image-based barcode scanning.

Call the following methods to set optional parameters:

  • setHmsScanTypes(int type): sets the supported barcode formats. Fewer formats speed up scanning. All formats supported by Scan Kit will be scanned by default.
  • setPhotoMode(boolean photoMode): sets whether to use the camera-based mode or image-based mode for barcode scanning. In this example, set the parameter to true (image-based mode). The default value is false (camera-based mode).
  • setMultiMode(boolean multiMode): sets whether to recognize a single barcode or multiple barcodes. The default value is false (single barcode).
  • setParseResult(boolean parseResul): sets whether to enable barcode parsing. Set the parameter to false if you only need the original scanning result. In this case, the format of the detected barcode will be returned in text via getScanType(). The default value is true (barcode parsing is enabled).
Java
 
"Java"
// QRCODE_SCAN_TYPE and PDF417_SCAN_TYPE indicate that only barcodes in the QR code format and PDF-417 format are supported. 
HmsScanFrameOptions option = new HmsScanFrameOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE| HmsScan.PDF417_SCAN_TYPE).setMultiMode(false).setParseResult(true).setPhotoMode(true).create();

"Kotlin" 
// QRCODE_SCAN_TYPE and PDF417_SCAN_TYPE indicate that only barcodes in the QR code format and PDF-417 format are supported. 
HmsScanFrameOptions option = new HmsScanFrameOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE| HmsScan.PDF417_SCAN_TYPE).setMultiMode(false).setParseResult(true).setPhotoMode(true).create()


3. Call decode (a static method) of ScanUtil to initiate a barcode scanning request and obtain the scanning result object HmsScanResult. For information contained in this object, please refer to Parsing Barcodes. If you do not have specific requirements on barcode formats, set options to null.

Java
 
"Java"
HmsScanResult result = ScanUtil.decode(BitmapActivity.this, frame, options); 
HmsScan[] hmsScans = result.getHmsScans(); 
// Process the scanning result. 
if (hmsScans != null && hmsScans.length > 0) { 
    // Display the scanning result. 
    ... 
}

"Kotlin"
val hmsScansResult= ScanUtil.decode(this@BitmapActivity, frame, option) 
val hmsScans = hmsScansResult.hmsScans 
// Process the scanning result. 
if (hmsScans != null && hmsScans.size > 0) { 
    // Display the scanning result. 
    ... 
}


That's all for the new releases in the latest version of the HMS Core Scan Kit. Leave a comment if you have any questions.

API Barcode

Published at DZone with permission of Jackson Jiang. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • How to Create a Successful API Ecosystem
  • MCP Servers: The Technical Debt That Is Coming

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: