Hi,
on a JAVA tutorial website I found a code for creating a QR code and saving it as PNG.
How can I use this code in LANSA in IBMi functions or Reusable Parts?
This is the code (some of the values have to submittable as parameters for using it in LANSA):
package com.journaldev.qrcode.generator;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class GenerateQRCode {
public static void main(String[] args) throws WriterException, IOException {
String qrCodeText = "https://www.journaldev.com";
String filePath = "JD.png";
int size = 125;
String fileType = "png";
File qrFile = new File(filePath);
createQRImage(qrFile, qrCodeText, size, fileType);
System.out.println("DONE");
}
private static void createQRImage(File qrFile, String qrCodeText, int size, String fileType)
throws WriterException, IOException {
// Create the ByteMatrix for the QR-Code that encodes the given String
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
// Make the BufferedImage that are to hold the QRCode
int matrixWidth = byteMatrix.getWidth();
BufferedImage image = new BufferedImage(matrixWidth, matrixWidth, BufferedImage.TYPE_INT_RGB);
image.createGraphics();
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, matrixWidth, matrixWidth);
// Paint and save the image using the ByteMatrix
graphics.setColor(Color.BLACK);
for (int i = 0; i < matrixWidth; i++) {
for (int j = 0; j < matrixWidth; j++) {
if (byteMatrix.get(i, j)) {
graphics.fillRect(i, j, 1, 1);
}
}
}
ImageIO.write(image, fileType, qrFile);
}
}
Many thanks for your help.
Joerg
Embedding Java functionality in LANSA
-
Joerg Hamacher
- Posts: 124
- Joined: Thu Feb 11, 2016 12:01 am
Re: Embedding Java functionality in LANSA
Hi Joerg,
I dont use JAVA neither I have a testing program to try it but if you want to take that route maybe you can just call the RUNJVA IBM command using SYSTEM_COMMAND builtin...
I dont use JAVA neither I have a testing program to try it but if you want to take that route maybe you can just call the RUNJVA IBM command using SYSTEM_COMMAND builtin...
-
Joerg Hamacher
- Posts: 124
- Joined: Thu Feb 11, 2016 12:01 am
Re: Embedding Java functionality in LANSA
Hi Dino,
I could realize it with SYSTEM_COMMAND after my son managed to rewrite it to a jar file.
Problem I see is that SYSTEM_COMMAND cannot work with more than 768 signs (3 command strings of 256) - and the string the QR code shall be created from can contain up to 700 characters....
Kind regards,
Joerg
I could realize it with SYSTEM_COMMAND after my son managed to rewrite it to a jar file.
Problem I see is that SYSTEM_COMMAND cannot work with more than 768 signs (3 command strings of 256) - and the string the QR code shall be created from can contain up to 700 characters....
Kind regards,
Joerg
Re: Embedding Java functionality in LANSA
in that case, maybe a CL is a better way to handle that and have LANSA call the CL program.
or even better, as you already going full java mode, have the java program read the file, just use the key in your call, not the whole super long value you want to use. I guess you can access the files from java, but if not, an example like this: https://www.w3schools.com/java/java_files_read.asp can read a txt file (I guess in the IFS), and you can put all the information you want in a text file in the IFS just transforming a list to file.
or even better, as you already going full java mode, have the java program read the file, just use the key in your call, not the whole super long value you want to use. I guess you can access the files from java, but if not, an example like this: https://www.w3schools.com/java/java_files_read.asp can read a txt file (I guess in the IFS), and you can put all the information you want in a text file in the IFS just transforming a list to file.
-
Joerg Hamacher
- Posts: 124
- Joined: Thu Feb 11, 2016 12:01 am
Re: Embedding Java functionality in LANSA
Hi Dino,
thank you once again for your help.
The last psot with creating a web service seems to be very interesting.
I will try this the next time when hopefully having more time for a java integrating project.
Due to time pressure (the project must be up and running by October 1), I chose the conservative solution with the CL program for this time.
Kind regards,
Joerg
thank you once again for your help.
The last psot with creating a web service seems to be very interesting.
I will try this the next time when hopefully having more time for a java integrating project.
Due to time pressure (the project must be up and running by October 1), I chose the conservative solution with the CL program for this time.
Kind regards,
Joerg