CapturePictureModule.java
6.06 KB
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
package com.huaheng.api.erp.domain;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.config.HuaHengConfig;
import com.netsdk.demo.module.LoginModule;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
public class CapturePictureModule {
public static boolean remoteCapturePicture(int chn, NetSDKLib.LLong m_hLoginHandle) {
return snapPicture(chn, 0, 0,m_hLoginHandle);
}
/**
* \if ENGLISH_LANG
* Capture Picture (except local capture picture, others all call this interface)
* \else
* 抓图 (除本地抓图外, 其他全部调用此接口)
* \endif
*/
private static boolean snapPicture(int chn, int mode, int interval, NetSDKLib.LLong m_hLoginHandle) {
// send caputre picture command to device
NetSDKLib.SNAP_PARAMS stuSnapParams = new NetSDKLib.SNAP_PARAMS();
stuSnapParams.Channel = chn; // channel
stuSnapParams.mode = mode; // capture picture mode
stuSnapParams.Quality = 3; // picture quality
stuSnapParams.InterSnap = interval; // timer capture picture time interval
stuSnapParams.CmdSerial = 0; // request serial
IntByReference reserved = new IntByReference(0);
if (!LoginModule.netsdk.CLIENT_SnapPictureEx(m_hLoginHandle, stuSnapParams, reserved)) {
System.err.printf("CLIENT_SnapPictureEx Failed!" + ToolKits.getErrorCodePrint());
return false;
} else {
System.out.println("CLIENT_SnapPictureEx success");
}
return true;
}
public static final CarInCaptureReceiveCB m_CarInCaptureReceiveCB = new CarInCaptureReceiveCB();
public static final CarOutCaptureReceiveCB m_CarOutCaptureReceiveCB = new CarOutCaptureReceiveCB();
public static final MaterialCaptureReceiveCB m_MaterialCaptureReceiveCB = new MaterialCaptureReceiveCB();
public static void setSnapRevCallBack(NetSDKLib.fSnapRev cbSnapReceive){
LoginModule.netsdk.CLIENT_SetSnapRevCallBack(cbSnapReceive, null);
}
public static class CarInCaptureReceiveCB implements NetSDKLib.fSnapRev {
@Override
public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) {
if (pBuf != null && RevLen > 0) {
String imgSavePath = QuantityConstant.CAR_IN_CAPTURE_IMAGE_ADDRESS;
// 创建存储目录
File path1 = new File(HuaHengConfig.getProfile()+"img/Capture");
if (!path1.exists()) {
path1.mkdirs();
}
String imgPath = null;
imgPath = HuaHengConfig.getProfile() + imgSavePath + ".jpg";
// 将照片数据写入文件
byte[] buf = pBuf.getByteArray(0, RevLen);
ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
try {
BufferedImage bufferedImage = ImageIO.read(byteArrInput);
if (bufferedImage == null) {
return;
}
ImageIO.write(bufferedImage, "jpg", new File(imgPath));//这里保存照片
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static class CarOutCaptureReceiveCB implements NetSDKLib.fSnapRev {
@Override
public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) {
if (pBuf != null && RevLen > 0) {
String imgSavePath = QuantityConstant.CAR_OUT_CAPTURE_IMAGE_ADDRESS;
// 创建存储目录
File path1 = new File(HuaHengConfig.getProfile()+"img/Capture");
if (!path1.exists()) {
path1.mkdirs();
}
String imgPath = null;
imgPath = HuaHengConfig.getProfile() + imgSavePath + ".jpg";
// 将照片数据写入文件
byte[] buf = pBuf.getByteArray(0, RevLen);
ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
try {
BufferedImage bufferedImage = ImageIO.read(byteArrInput);
if (bufferedImage == null) {
return;
}
ImageIO.write(bufferedImage, "jpg", new File(imgPath));//这里保存照片
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static class MaterialCaptureReceiveCB implements NetSDKLib.fSnapRev {
@Override
public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) {
if (pBuf != null && RevLen > 0) {
String imgSavePath = QuantityConstant.MATERIAL_CAPTURE_IMAGE_ADDRESS;
// 创建存储目录
File path1 = new File(HuaHengConfig.getProfile()+"img/Capture");
if (!path1.exists()) {
path1.mkdirs();
}
String imgPath = null;
imgPath = HuaHengConfig.getProfile() + imgSavePath + ".jpg";
// 将照片数据写入文件
byte[] buf = pBuf.getByteArray(0, RevLen);
ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
try {
BufferedImage bufferedImage = ImageIO.read(byteArrInput);
if (bufferedImage == null) {
return;
}
ImageIO.write(bufferedImage, "jpg", new File(imgPath));//这里保存照片
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}