houzhongjian
2024-11-14 08b6a55a3a111aaee9842999b85afa60b6d61dc3
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
package com.iailab.module.data.video.dahua;
 
import com.iailab.module.data.video.config.VideoConfiguration;
import com.iailab.module.data.video.service.CameraService;
import com.iailab.netsdk.lib.NetSDKLib;
import com.sun.jna.Pointer;
 
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 设置抓图回调
 *
 * @author PanZhibao
 * @Description
 * @createTime 2024年03月06日
 */
public class DHCaptureReceiveCB implements NetSDKLib.fSnapRev {
 
    @Resource
    private CameraService cameraService;
 
    @Override
    public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int revLen, int encodeType, int cmdSerial, Pointer dwUser) {
        System.out.println("DHCaptureReceiveCB:");
        Calendar calendar = Calendar.getInstance();
        if (pBuf != null && revLen > 0) {
            String strFileName = DHSavePath.getSavePath().getSaveCapturePath(String.valueOf(cmdSerial), calendar.getTime());
            System.out.println("cmdSerial=" + cmdSerial);
            System.out.println("strFileName=" + strFileName);
 
            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(strFileName));
            } catch (IOException e) {
                e.printStackTrace();
            }
 
            // 处理图片
            Map<String, String> params = new HashMap<>();
            params.put("strFileName", strFileName);
            params.put("cmdSerial", Integer.valueOf(cmdSerial).toString());
            params.put("brand", "DH");
            cameraService.dealCapture(params);
        }
    }
}