In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how Java generates QR code pictures". In daily operation, I believe many people have doubts about how Java generates QR code pictures. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to generate QR code pictures by Java". Next, please follow the editor to study!
Brief introduction
ZXing is an open source Java library for parsing 1D/2D barcodes in multiple formats. The goal is to be able to decode 1D barcodes of QR coding, Data Matrix and UPC. It provides clients on a variety of platforms, including J2ME, J2SE and Android. Official website: ZXing github warehouse practice this example demonstrates how to use ZXing to generate and parse QR code images in a non-android Java project. Install maven project only need to introduce dependency: com.google.zxing core 3.3.0 com.google.zxing javase 3.3.0 if not maven project, go to the official website to download the release version: download address to generate QR code picture ZXing to generate QR code picture has the following steps: 1. Com.google.zxing.MultiFormatWriter generates image 2D matrix based on content and image coding parameters.
2. Com.google.zxing.client.j2se.MatrixToImageWriter generates a picture file or image cache BufferedImage according to the image matrix.
Public void encode (String content, String filepath) throws WriterException, IOException {int width = 100; int height = 100; Map encodeHints = new HashMap (); encodeHints.put (EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix = new MultiFormatWriter (). Encode (content, BarcodeFormat.QR_CODE, width, height, encodeHints); Path path = FileSystems.getDefault (). GetPath (filepath); MatrixToImageWriter.writeToPath (bitMatrix, "png", path) } parsing QR code pictures ZXing parsing QR code pictures have the following steps: 1. Use javax.imageio.ImageIO to read the picture file and save it as a java.awt.image.BufferedImage object. two。 Convert java.awt.image.BufferedImage to a com.google.zxing.BinaryBitmap object that ZXing recognizes. 3. Com.google.zxing.MultiFormatReader parses the com.google.zxing.BinaryBitmap according to the image decoding parameters. Public String decode (String filepath) throws IOException, NotFoundException {BufferedImage bufferedImage = ImageIO.read (new FileInputStream (filepath)); LuminanceSource source = new BufferedImageLuminanceSource (bufferedImage); Binarizer binarizer = new HybridBinarizer (source); BinaryBitmap bitmap = new BinaryBitmap (binarizer); HashMap decodeHints = new HashMap (); decodeHints.put (DecodeHintType.CHARACTER_SET, "UTF-8"); Result result = new MultiFormatReader (). Decode (bitmap, decodeHints); return result.getText () At this point, the study on "how to generate a QR code picture by Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.