我正在使用Digital Persona U.Are.U 4500,并且我已经从硬件安装了指纹SDK。我正在使用Java API,并且能够在Java中运行示例代码。现在,我正在尝试将指纹数据另存为图像。有什么方法可以将其保存为图像,任何格式,只要我可以将其保存在计算机中并将其作为图像查看即可。谢谢!
我意识到"evt.capture_result.image"的数据类型为Fid。我认为这可能会对我有所帮助,但我不知道如何将 Fid 文件转换为字节[]。还是我错了?
这是捕获类,我希望在这里更改一些代码。
package fp;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import com.digitalpersona.javapos.services.biometrics.CaptureThread;
import com.digitalpersona.uareu.*;
import com.digitalpersona.uareu.Fid.Fiv;
import static sun.security.krb5.Confounder.bytes;
public class Capture extends JPanel implements ActionListener {
private static final long serialVersionUID = 2;
private static final String ACT_BACK = "back";
private JDialog m_dlgParent;
private CaptureThread m_capture;
private Reader m_reader;
private ImagePanel m_image;
private Fid m_fid; //fid
private Fiv m_fiv; //fiv
private boolean m_bStreaming;
private Capture(Reader reader, boolean bStreaming){
m_reader = reader;
m_bStreaming = bStreaming;
m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);
final int vgap = 5;
BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
setLayout(layout);
m_image = new ImagePanel();
Dimension dm = new Dimension(380, 380);
m_image.setPreferredSize(dm);
add(m_image);
add(Box.createVerticalStrut(vgap));
JButton btnBack = new JButton("Back");
btnBack.setActionCommand(ACT_BACK);
btnBack.addActionListener(this);
add(btnBack);
add(Box.createVerticalStrut(vgap));}
private void StartCaptureThread(){
m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);
m_capture.start(this);
}
private void StopCaptureThread(){
if(null != m_capture) m_capture.cancel();
}
private void WaitForCaptureThread(){
if(null != m_capture) m_capture.join(1000);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals(ACT_BACK)){
//event from "back" button
//cancel capture
StopCaptureThread();
}
else if(e.getActionCommand().equals(CaptureThread.ACT_CAPTURE)){
//event from capture thread
CaptureThread.CaptureEvent evt = (CaptureThread.CaptureEvent)e;
boolean bCanceled = false;
if(null != evt.capture_result){
if(null != evt.capture_result.image && Reader.CaptureQuality.GOOD == evt.capture_result.quality){
//display image
m_image.showImage(evt.capture_result.image);
}
else if(Reader.CaptureQuality.CANCELED == evt.capture_result.quality){
//capture or streaming was canceled, just quit
bCanceled = true;
}
else{
//bad quality
MessageBox.BadQuality(evt.capture_result.quality);
}
}
else if(null != evt.exception){
//exception during capture
MessageBox.DpError("Capture", evt.exception);
bCanceled = true;
}
else if(null != evt.reader_status){
MessageBox.BadStatus(evt.reader_status);
bCanceled = true;
}
if(!bCanceled){
if(!m_bStreaming){
//restart capture thread
WaitForCaptureThread();
StartCaptureThread();
}
}
else{
//destroy dialog
m_dlgParent.setVisible(false);
}
}
}
private void doModal(JDialog dlgParent){
//open reader
try{
m_reader.Open(Reader.Priority.COOPERATIVE);
}
catch(UareUException e){ MessageBox.DpError("Reader.Open()", e); }
boolean bOk = true;
if(m_bStreaming){
//check if streaming supported
Reader.Capabilities rc = m_reader.GetCapabilities();
if(!rc.can_stream){
MessageBox.Warning("This reader does not support streaming");
bOk = false;
}
}
if(bOk){
//start capture thread
StartCaptureThread();
//bring up modal dialog
m_dlgParent = dlgParent;
m_dlgParent.setContentPane(this);
m_dlgParent.pack();
m_dlgParent.setLocationRelativeTo(null);
m_dlgParent.toFront();
m_dlgParent.setVisible(true);
m_dlgParent.dispose();
//cancel capture
StopCaptureThread();
//wait for capture thread to finish
WaitForCaptureThread();
}
//close reader
try{
m_reader.Close();
}
catch(UareUException e){ MessageBox.DpError("Reader.Close()", e); }
}
public static void Run(Reader reader, boolean bStreaming){
JDialog dlg = new JDialog((JDialog)null, "Put your finger on the reader", true);
Capture capture = new Capture(reader, bStreaming);
capture.doModal(dlg);
}
}
OP在回复@LaurentY的评论中添加:
我想我找到了一种使用您给我的类以图像格式保存的方法,方法是在repaint ();
后添加下面的代码
//saving file
File png = new File ("C://Users//HP//Documents//.Fingerprints Iseng//"+x+".png");
try
{
ImageIO.write(m_image,"png",png);
}
catch (IOException ex)
{
Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Done Saving..");
我认为您的代码来自此存储库 https://github.com/ankit4u3/Digital-Persona
在这个存储库中,有一个类来显示来自 Fid 的图像:https://github.com/ankit4u3/Digital-Persona/blob/master/src/ImagePanel.java
这里的代码:
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import com.digitalpersona.uareu.Fid;
import com.digitalpersona.uareu.Fid.Fiv;
public class ImagePanel extends JPanel {
private static final long serialVersionUID = 5;
private BufferedImage m_image;
public void showImage(Fid image) {
Fiv view = image.getViews()[0];
m_image = new BufferedImage(view.getWidth(), view.getHeight(),
BufferedImage.TYPE_BYTE_GRAY);
m_image.getRaster().setDataElements(0, 0, view.getWidth(),
view.getHeight(), view.getImageData());
repaint();
}
@Override
public void paint(Graphics g) {
g.drawImage(m_image, 0, 0, null);
}
}