The photo information read by a card reader such as an ID card is generally stored in the Access database as an OLE field, and the picture is in BMP format, because it is written by its card reader, and its data type is constant binary data.
When the report or EXCEL is used to read these pictures, if the picture field is dragged into the cell, the preview cannot see the picture. There are online tutorials on how EXCEL reads such pictures, so I won't say much here. What if you want to use the reporting software FineReport to display such pictures?
The idea is to use the custom function of FineReport , use java 's jna to call the local WltRS.dll , convert the long binary data in the OLE field of the database into a .wlt file, and then call the local method to convert the .wlt file into a .bmp image, and finally The picture returned by the custom function is displayed in FineReport .
<!--[if !supportLists]--> 1. <!--[endif]--> Prerequisites
The native library file WltRS.dll is saved in E:\bmp\WltRS.dll (the location is variable, but ixu guarantees the same path in the custom function); the jar package of FINEREPORT is imported in the eclipse project .
<!--[if !supportLists]--> 2. <!--[endif]--> Implement custom functions
Customize a function class BinaryImage.java , which inherits AbstractFunction , uses java 's jna to call the native library file WltRS.dll in the run() method , and finally returns the image. code show as below:
package com.FineReport.function; import java.awt.image.BufferedImage; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.FineReport.data.core.db.BinaryObject; import com.FineReport.script.AbstractFunction; import com.sun.jna.Library; import com.sun.jna.Native; public class BinaryImage extends AbstractFunction{ //Load the dll, "E:\\bmp\\WltRS" is the full path of the dll's file, but without the suffix name, generate WltRS.class static WltRS wltrs = (WltRS) Native.loadLibrary("E:\\bmp\\WltRS", WltRS.class); static int index = 0; public Object run(Object[] args) { int current = index; //args[0] is the BinaryObject object, which is taken as bo BinaryObject bo = (BinaryObject)args[0]; //Convert bo to .wlt file and save it in the location E:\bmp\; the first parameter of the local method GetBmp is the path of the wlt file getFile(bo.getBytes(), "E:\\bmp\\", current + ".wlt"); //Read .wlt as a file File file = new File("E:\\bmp\\" + current + ".wlt"); //Call the local method and produce .bmp in the same path wltrs.GetBmp("E:\\bmp\\" + current + ".wlt", 1); //read and return the image File imagefile = new File("E:\\bmp\\" + current + ".bmp"); BufferedImage buffer = null; try { buffer = ImageIO.read(imagefile); } catch (IOException e) { e.printStackTrace (); } index = (++index)%300; return buffer; } // method of converting byte[] to file public static void getFile(byte[] bfile, String filePath, String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if(!dir.exists() && dir.isDirectory()){//Determine whether the file directory exists dir.mkdirs(); } file = new File(filePath+"\\"+fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bfile); } catch (Exception e) { e.printStackTrace (); } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } } } //The necessary steps to call a local method with jna, the specific meaning is unknown interface WltRS extends Library{ //Define the local method to call void GetBmp(String str, int i); }
Copy the compiled BinaryImage.class and WltRS.class to the report project such as WebReport\WEB-INF\classes\com\FineReport\function\ folder under the report installation directory according to the package name.
3. Use custom functions
Displays the value of an OLE type field as a picture. Start the designer, click Server > Function Manager, add a custom function BINARYIMAGE , and select the com.FineReport.function.BinaryImage class:
Drag the photo information written by the ID card reader into the OLE field of the Access database into the cell, double-click, and use a custom function to convert it into a picture in Data Column > Advanced > Custom Display: