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?
Related
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?
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;
}
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}}"/>
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
Out-of-the-box ArrayIndexOutOfBoundsException when attempting to use Apache-Commons Sanselan to load a TIFF that was compressed with PackBits compression.
Code:
import org.apache.sanselan.*;
public class TIFFHandler {
public static Image loadTIFF(String fileName) throws ImageReadException, IOException {
File imageFile = new File(fileName);
BufferedImage bi = Sanselan.getBufferedImage(imageFile);
return bi;
}
public static void main(String[] args) throws IOException, ImageReadException {
String TIFFFILE = "test_image.tif";
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
BufferedImage bi = (BufferedImage) loadTIFF(TIFFFILE);
ImageIcon ii = new ImageIcon(bi);
JLabel lbl = new JLabel(ii);
panel.add(lbl);
frame.setVisible(true);
}
}
Stack trace:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 426
at org.apache.sanselan.common.PackBits.decompress(PackBits.java:55)
at org.apache.sanselan.formats.tiff.datareaders.DataReader.decompress(DataReader.java:127)
at org.apache.sanselan.formats.tiff.datareaders.DataReaderStrips.readImageData(DataReaderStrips.java:96)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:505)
at org.apache.sanselan.formats.tiff.TiffDirectory.getTiffImage(TiffDirectory.java:163)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:441)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1264)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1255)
at TIFFHandler.loadTIFF(FieldSheetHandler.java:42)
at TIFFHandler.main(FieldSheetHandler.java:90)
I've attempted an analysis of the problem, but I'm pretty lost...any directions would be really helpful. TIFF images are a pain in the a**.
You can try the updated version of Commons Imaging from the Apache snapshot repository. The Javadoc is not online yet, you'll have to build it by checking out the code from SVN and running mvn javadoc:javadoc.
If you find more issues or want to suggest an improvement you can file them in JIRA. Also the developers will be happy to help you if you have questions regarding the usage of the API. They await you on the mailing list.