提交 | 用户 | 时间
149dd0 1 package com.iailab.module.data.video.dahua;
H 2
3 import com.alibaba.fastjson.JSON;
4 import com.iailab.module.data.common.utils.HttpRequest;
5 import com.iailab.netsdk.lib.NetSDKLib;
6 import com.sun.jna.Pointer;
7 import org.springframework.beans.factory.annotation.Value;
8
21dc7e 9 import javax.annotation.PostConstruct;
149dd0 10 import javax.imageio.ImageIO;
H 11 import java.awt.image.BufferedImage;
12 import java.io.ByteArrayInputStream;
13 import java.io.File;
14 import java.io.IOException;
15 import java.util.Calendar;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 /**
20  * 设置抓图回调
21  *
22  * @author PanZhibao
23  * @Description
24  * @createTime 2024年03月06日
25  */
26 public class DHCaptureReceiveCB implements NetSDKLib.fSnapRev {
27
28     @Override
29     public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int revLen, int encodeType, int cmdSerial, Pointer dwUser) {
30         System.out.println("DHCaptureReceiveCB:");
31         Calendar calendar = Calendar.getInstance();
32 //        calendar.set(Calendar.MONTH, 0);
33 //        calendar.set(Calendar.SECOND, 0);
34         if (pBuf != null && revLen > 0) {
35             String strFileName = DHSavePath.getSavePath().getSaveCapturePath(String.valueOf(cmdSerial), calendar.getTime());
36             System.out.println("cmdSerial=" + cmdSerial);
37             System.out.println("strFileName=" + strFileName);
38
39             byte[] buf = pBuf.getByteArray(0, revLen);
40             ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
41             try {
42                 BufferedImage bufferedImage = ImageIO.read(byteArrInput);
43                 if (bufferedImage == null) {
44                     return;
45                 }
46                 ImageIO.write(bufferedImage, "jpg", new File(strFileName));
47             } catch (IOException e) {
48                 e.printStackTrace();
49             }
50
51             // 回调处理图片
52             Map<String, String> params = new HashMap<>();
53             params.put("strFileName", strFileName);
54             params.put("cmdSerial", Integer.valueOf(cmdSerial).toString());
21dc7e 55             HttpRequest.doPost(DHConfiguration.staticUrl, JSON.toJSONString(params), "utf-8", "");
149dd0 56
H 57         }
58     }
59 }