fuliqi
2024-08-29 4163c93761115c7524ef74a557a1f5e01eafb429
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
package com.ycl.api.YS.liveview.live;
 
import com.sun.jna.Native;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_RECT_S;
 
import javax.swing.*;
import java.util.InputMismatchException;
 
/**
 * 
 * @introduction DigitalZoom
 * @description Support IPC/NVR/VMS
 */
public class DigitalZoom {
    
    /**
     * 
     * @introduction Set DigitalZoom
     * @description Calling the interface of NETDEV_SetDigitalZoom to set the digitalZoom, 
     * the parameter should between 0 and 10000
     *
     */
    public static void setDigitalZoom() {
        if(null == NetDemo.lpUserID) {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
            }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel.");
            return;
        }
        
        int dwLeft=0;
        int dwTop=0;
        int dwRight=0;
        int dwBottom=0;        
        try {
            dwLeft=Integer.parseInt(NetDemo.jTextFieldDigitalZoomLeft.getText());
        }catch(NumberFormatException |InputMismatchException e) {
            JOptionPane.showMessageDialog(null, "Left parameter is null or transformation exception");
            NetDemo.jTextFieldDigitalZoomLeft.setText(null);
            return;
        }        
        if(dwLeft<0||dwLeft>10000) {
            JOptionPane.showMessageDialog(null, "Left parameter should beteen 0~10000");
            return;
        }
        
        try {
            dwTop=Integer.parseInt(NetDemo.jTextFieldDigitalZoomTop.getText());
        }catch(NumberFormatException |InputMismatchException e) {
            JOptionPane.showMessageDialog(null, "Top parameter is null or transformation exception");
            return;
        }    
        if(dwTop<0||dwTop>10000) {
            JOptionPane.showMessageDialog(null, "Top parameter should beteen 0~10000");
            return;
        }
        
        try {
            dwRight=Integer.parseInt(NetDemo.jTextFieldDigitalZoomRight.getText());
        }
        catch(NumberFormatException | InputMismatchException e) {
            JOptionPane.showMessageDialog(null, "Right parameter is null or transformation exception");
            return;
        }        
        if(dwRight<0||dwRight>10000) {
            JOptionPane.showMessageDialog(null, "Right parameter should beteen 0~10000");
            return;
        }
        
        try {
            dwBottom=Integer.parseInt(NetDemo.jTextFieldDigitalZoomBottom.getText());
        }catch(NumberFormatException |InputMismatchException e) {
            JOptionPane.showMessageDialog(null, "Bottom parameter is null or transformation exception");
            return;
        }
        if(dwBottom<0||dwBottom>10000) {
            JOptionPane.showMessageDialog(null, "Bottom parameter should beteen 0~10000");
            return;
        }
        
        if(dwBottom<=dwTop) {
            JOptionPane.showMessageDialog(null, "Bottom must more than top");
            return;
        }
        if(dwRight<=dwLeft) {
            JOptionPane.showMessageDialog(null, "Right must more than left");
            return;
        }
        
        NETDEV_RECT_S pstRect=new NETDEV_RECT_S();
        pstRect.dwLeft=dwLeft;
        pstRect.dwTop=dwTop;
        pstRect.dwRight=dwRight;
        pstRect.dwBottom=dwBottom;
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDigitalZoom(NetDemo.lpPlayHandle,Native.getComponentPointer(NetDemo.panelPlayLabel),pstRect);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Set Digital Zoom. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_SetDigitalZoom failed, error:" + NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "Success");
        }
    }
    
    /**
     * 
     * @introduction Exit DigitalZoom
     * @description Calling the interface of NETDEV_SetDigitalZoom and set the NETDEV_RECT_S null to exie digitalzoom
     *
     */
    public static void closeDigitalZoom() {
        if(null == NetDemo.lpUserID) {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
            }
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDigitalZoom(NetDemo.lpPlayHandle,Native.getComponentPointer(NetDemo.panelPlayLabel),null);
        if(bRet != true)
        {
            System.out.printf("NETDEV_SetDigitalZoom failed, error:" + NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
    }
}