-
Notifications
You must be signed in to change notification settings - Fork 1
/
imgprocess.java
157 lines (149 loc) · 3.98 KB
/
imgprocess.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import javax.swing.*;
import javax.imageio.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import SecuGen.FDxSDKPro.jni.*;
class IMGProcess extends JFrame
{
JSGFPLib o;
private BufferedImage localBufferedImage;
private byte[] arrayOfByte;
private JLabel imgShow;
private JTextField devName;
private JButton init,capture,savebmp;
private JPanel imgContainer;
public IMGProcess()
{
initComponents();
setLayout(null);
setTitle("Secugen Image Processing");
setSize(550,400);
setVisible(true);
}
private void initComponents()
{
imgShow = new JLabel();
imgShow.setBorder(BorderFactory.createLineBorder(Color.red));
imgShow.setBounds(50,50,350,260);
devName= new JTextField("Secugen Hamster Pro 20");
devName.setBounds(10,20,150,20);
devName.setEnabled(false);
init=new JButton("Initialize");
init.setBounds(200,20,100,20);
init.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
initialize();
}
});
capture= new JButton("Capture");
capture.setBounds(340,20,100,20);
capture.setEnabled(false);
capture.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
captureImage();
}
});
savebmp= new JButton("Save Image As BMP");
savebmp.setBounds(150,320,150,20);
savebmp.setEnabled(false);
savebmp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
saveImage();
}
});
/*imgContainer =new JPanel();
imgContainer.setLayout(null);
imgContainer.setBorder(BorderFactory.createLineBorder(Color.black));
imgContainer.add(imgShow);
imgContainer.setBounds(50,50,350,260);*/
add(devName);
add(init);
add(capture);
add(savebmp);
//getContentPane().add(imgContainer);
add(imgShow);
}
private void initialize()
{
//JSGFPLib o =new JSGFPLib((UsbManager)getSystemService(Context.USB_SERVICE));
o =new JSGFPLib();
long device = o.Init(SGFDxDeviceName.SG_DEV_FDU05);
long opesuccess = o.OpenDevice(SGPPPortAddr.USB_AUTO_DETECT);
if(opesuccess==SGFDxErrorCode.SGFDX_ERROR_NONE)
{
JOptionPane.showMessageDialog(null,"Device Initialized successfully");
capture.setEnabled(true);
}
}
private void captureImage()
{
long error=0;
int img_w=0,img_h=0;
//byte[] buffer=new byte[img_w*img_h];
//JOptionPane.showMessageDialog(null,"1");
SGDeviceInfoParam deviceInfo = new SGDeviceInfoParam();
//JOptionPane.showMessageDialog(null,"2");
long e = o.GetDeviceInfo(deviceInfo);
//JOptionPane.showMessageDialog(null,"3");
if(e==SGFDxErrorCode.SGFDX_ERROR_NONE)
{
//JOptionPane.showMessageDialog(null,"4");
img_w=deviceInfo.imageWidth;
img_h=deviceInfo.imageHeight;
}
localBufferedImage = new BufferedImage(img_w,img_h,10);
arrayOfByte = ((DataBufferByte)localBufferedImage.getRaster().getDataBuffer()).getData();
//////// Getting Image
try
{
error=o.GetImage(arrayOfByte);
}
catch(Exception er)
{
er.printStackTrace();
}
if(error==SGFDxErrorCode.SGFDX_ERROR_NONE)
{
imgShow.setIcon(new ImageIcon(localBufferedImage));
//JOptionPane.showMessageDialog(null,"5");
JOptionPane.showMessageDialog(null,"Image captured successfully");
savebmp.setEnabled(true);
}
}
private void saveImage()
{
boolean test=false,done=false;
String path="C:/Users/HnH/Videos/java application/bitmap/";
File output;
String s;
/*do
{
s = (String)JOptionPane.showInputDialog(this,"Enter File name");
if(s!=null && s.length()>0)
{
test=true;
}
}while(test==false);*/
try
{
RenderedImage rImg =localBufferedImage;
done = ImageIO.write(rImg,"bmp",new File(path+"harry.bmp"));
}
catch(Exception er1)
{
er1.printStackTrace();
}
if(done == true)
{
imgShow.setIcon(null);
savebmp.setEnabled(false);
JOptionPane.showMessageDialog(null,"File saved successfully.");
}
}
public static void main(String[] args)
{
new IMGProcess();
}
}