我想获取指纹图像,将其显示到标签并将其保存为位图文件。将手指滑动到阅读器后,将生成图像,并且该图像必须以标签显示然后保存。这是我的代码:
static class ABS_IMAGE
{
int width;
int height;
int colorCount;
int horizontalDpi;
int verticalDpi;
byte [] ImageData;
ABS_IMAGE()
{
ImageData = new byte[55296];
}
}
public class displayImage
{
private ABS_IMAGE _image = new ABS_IMAGE();
BufferedImage bufferedImage = new BufferedImage(_image.width, _image.height, BufferedImage.TYPE_BYTE_GRAY);
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(null, "bmp");
fileChooser.setFileFilter(filter);
if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
{
try {
// Save the image as bitmap file
File file = new File("", fileChooser.getSelectedFile().getName() + ".bmp");
ImageIO.write(bufferedImage, "bmp", new File("filename.bmp"));
} catch (IOException e) {
e.printStackTrace();
}
}
// Display Finger print image
FingerPrintImage formFingerPrintImage = new FingerPrintImage(this, true, _image.width, _image.height, _image.ImageData);
formFingerPrintImage.setVisible(true);
}
这是显示图像的第二种形式的代码:
public FingerPrintImage(java.awt.Frame parent, boolean modal, int width, int height, byte[] imageData)
{
super(parent, modal);
initComponents();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension size = this.getSize();
screenSize.height = screenSize.height/2;
screenSize.width = screenSize.width/2;
size.height = size.height/2;
size.width = size.width/2;
int y = screenSize.height - size.height;
int x = screenSize.width - size.width;
this.setLocation(x, y);
_fpWidth = width;
_fpHeight = height;
_image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
displayImage(imageData);
src = toBufferedImage(_image);
ImageIcon icon = new ImageIcon(src);
LabelImage.setIcon(icon);
}
private void initComponents()
{
setResizable(false);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 238, 494);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton ButtonOk = new JButton("OK");
ButtonOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
ButtonOk.setBounds(133, 432, 89, 23);
contentPane.add(ButtonOk);
LabelImage = new JLabel("");
LabelImage.setBounds(10, 11, 212, 410);
contentPane.add(LabelImage);
}
private void displayImage(byte[] imageData)
{
int ctr = 0;
for(int j = 0; j < this._fpHeight; j++)
{
for(int i = 0; i < this._fpWidth; i++)
{
_image.setRGB(i, j, imageData[ctr]);
ctr++;
}
}
}
public void paint(Graphics g)
{
g.drawImage(src, (this.getSize().width - _fpWidth) / 2, (this.getSize().height - _fpHeight) / 2 , null); // see javadoc for more info on the parameters
g.setColor(Color.red);
}