How to detect that QRCode is scanned? - java

I have a Spring web application and I send an email to users and that email includes a QR code. How can I detect that the QR code is scanned with any phone? I want to detect that process in my web application. I have to do something when the QR code is scanned. However I cannot find how I can make it. Should I use websocket?
Here are my codes:
private JavaMailSender emailSender;
// ....
MimeMessage message = emailSender.createMimeMessage();
byte[] qrImageBytes = QRGenBarcodeGenerator.getQRCodeImage("text", 250, 250);
ByteArrayDataSource qrImageDataSource = new ByteArrayDataSource(qrImageBytes, "image/png");
helper.addAttachment("qrcode",qrImageDataSource);
emailSender.send(message);
getQrCodeImage function
public static byte[] getQRCodeImage(String text, int width, int height) throws WriterException, IOException {
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream);
byte[] pngData = pngOutputStream.toByteArray();
return pngData;
}

Related

How can I use custom font in Jeuclid (Java)?

this is the code where I am converting MathMl to png
public static void main(String[] args) throws IOException, FontFormatException {
Converter converter = Converter.getInstance();
String math="<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mfenced open=\"[\" close=\"]\"><mtable><mtr><mtd><mn>3</mn></mtd><mtd><mn>2</mn></mtd></mtr><mtr><mtd><mn>6</mn></mtd><mtd><mn>7</mn></mtd></mtr><mtr><mtd><mn>6</mn></mtd><mtd><mn>4</mn></mtd></mtr></mtable></mfenced><mo>=</mo><msubsup><mo>∫</mo><mn>5</mn><mn>4</mn></msubsup></math>";
File inputFile = new File("D:\\mathml.xml");
File outputFile = new File("D:\\image.jpg");
//params to mention the size of image
MutableLayoutContext params = new LayoutContextImpl(
LayoutContextImpl.getDefaultLayoutContext());
params.setParameter(Parameter.MATHSIZE, 50f);
Document doc = StringToDocumentToString.convertStringToDocument(math);
// Parameter parameter= new Pa
converter.convert(doc, outputFile , "image/jpeg", params);
}
I want to use Tahoma.ttf when I make png from MathMl but I can not find any resource how to do that. Please can anyone help me?

how to use Images without path in handlebars

I want to deliver image list into Handlebars view.
ArrayList<ImageIcon> images = new ArrayList<>();
for(Photos p : photos){
ByteArrayInputStream bis = new ByteArrayInputStream(p.getImage());
BufferedImage bim = ImageIO.read(bis);
images.add(new ImageIcon(bim));
}
model.addAttribute("photos", images);
I'm sure that there are ImageIcon objects in this arrayList by debugging.
Then, how can I use this array in handlebars like this.
{{#each photos as |photo|}}
<img src={{photo}}>
{{/each}}
I want to use this images without file path.
#GetMapping("/displayImage")
public void displayImage(#RequestParam("email")String email, HttpServletResponse response) throws IOException {
List<Photos> list = photoService.showImages(email);
byte[] binaryImage = list.get(0).getImage();
response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
response.getOutputStream().write(binaryImage);
response.getOutputStream().close();
}
<img src="/displayImage/?email={{userInfo.email}}"/>

How to display uploaded image via CSS

i want to upload an image via primefaces:fileUpload and then display it on a div for example with css.
I can already save the image on the server:
public void upload() throws IOException, URISyntaxException {
if (logo != null) {
File fileImage = new File(System.getProperty("jboss.server.data.dir"), "uploads.png");
BufferedImage img = ImageIO.read(new ByteArrayInputStream(logo.getContents()));
if (fileImage.exists()) {
fileImage.delete();
}
ImageIO.write(img, "png", fileImage);
}
}
And then i tried to get the web path to the file but that didn't worked:
public String getImagePath(){
File fileImage = new File(System.getProperty("jboss.server.data.dir"), "uploads.png");
Set<String> set = FacesContext.getCurrentInstance().getExternalContext().getResourcePaths(fileImage.getAbsolutePath());
return set.iterator().next();
}
I need something like this:
/ewarehouse/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&v=6.2&v=6.2&pfdrid=f52e395e4f38c09a1990e8f9d0c5806d&pfdrt=sc&pfdrid_c=true
Can someone help me or has a other way to do this ?
It worked for me to create a servlet and refered to the file position.
background-image: url('#{'/'}ewarehouse#{'/'}images//dynamic#{'/'}?file=uploads.png')
In css it look a bit weird but this way it worked Thanks for the answer to #JasperdeVries and #Kukeltje

Decoding QR code in photo using Zxing

I want to decode some photos with QR code.
I found this method:
public static String readQRCode(String filePath, String charset, Map hintMap) throws FileNotFoundException, IOException, NotFoundException {
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(
ImageIO.read(new FileInputStream(filePath)))));
Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap);
return qrCodeResult.getText();
}
It's working on pictures like this.
Unfortunately it doesn't work on all images, i.e: this. As you see it has poor quality.
Error: com.google.zxing.NotFoundException
Any ideas, what can I do?

How to zoom and scroll SVGs in Vaadin 7

I created a SVG image in java with batik and I managed to display it with vaadin embedded.
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
String svgNamespaceURI = "http://www.w3.org/2000/svg";
// Create an instance of org.w3c.dom.Document
Document document =
domImpl.createDocument(svgNamespaceURI, "svg", null);
svgGen = new SVGGraphics2D(document);
svgGen.setPaint(Color.green);
svgGen.drawPolyline(new int[]{70, 70, 30}, new int[]{50, 30, 70}, 3);
Displaying the SVG in vaadin
Writer writer = new OutputStreamWriter(out);
svgGen.stream(writer, useCSS);
StreamSource source = new StreamSource() {
private static final long serialVersionUID = -4905654404647215809L;
public InputStream getStream() {
return new ByteArrayInputStream(out.toByteArray());
}
};
// create a StreamResource
String filename = "svg" + System.currentTimeMillis() + ".svg";
StreamResource stream = new StreamResource(source, filename);
embedded= new Embedded();
embedded.setSizeFull();
embedded.setMimeType("image/svg+xml");
embedded.setSource(stream);
mainLayout.addComponent(embedded);
I now want to zoom and scroll the image and expected the Embedded to provide this functionality.
After searching for a while I haven't found a working solution so far.
The Question is, how can I enable scrolling and zooming the SVG-Image?

Categories

Resources