0

While working on a project for a restaurant, where the user has a QrCode containing his ID and the ID of the reservation then later be scanned at the counter.

This is the sample code I m working with :

 protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String productId = request.getParameter("productId");
        response.setContentType("image/png");
        OutputStream outputStream = response.getOutputStream();
        outputStream.write(getQRCodeImage(productId, 400, 400));
        outputStream.flush();
        outputStream.close();
    }

    private byte[] getQRCodeImage(String text, int width, int height) {
        try {
            QRCodeWriter qrCodeWriter = new QRCodeWriter();
            BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(bitMatrix, "png", byteArrayOutputStream);
            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            return null;
        }
    }

It shows me an Image containing the data I intended to insert. The thing is I want to store those images in a folder that will be kept on the server. PS : Those images will be later scanned by a smartphone application that I'll start on it later.

Zied Orabi
  • 49
  • 6

0 Answers0