Based on the Conway SDK javac/s

Source: Internet
Author: User

Download SDK Development Package configuration file directory for Lib/hc/hcnetsdkpublic HCNETSDK based on the Javac/shttp://www.hikvision.com/cn/download_61.html SDK INSTANCE = Commontools.loadlibrary (Commontools.getlibpath () + "\\hc\\HCNetSDK", Hcnetsdk.class); The SDK initializes private void Initsdk () {Boolean initsuccess = Hcnetsdk.net_dvr_init (); if (!initsuccess) {showmessage (" Initialization failed HCNETSDK: "+ geterrormessage (Instance.net_dvr_getlasterror ())); return;} Hcnetsdk.net_dvr_setconnecttime (2000, 1);} Connection device private void login (string IP, short port, string username, string passwd) {if (UserID! = null && USERID.LONGVA Lue () >= 0) {hcnetsdk.net_dvr_logout (userid);} Net_dvr_deviceinfo_v30 lpdeviceinfo = new Net_dvr_deviceinfo_v30 ();//second Step UserID = HCNETSDK.NET_DVR_LOGIN_V30 (IP, Port, Username, passwd,lpdeviceinfo); if (Hcnetsdk.net_dvr_getlasterror ()! = 0) {userid = new Nativelong ( -1); ShowMessage (" Login failed: "+ geterrormessage (Hcnetsdk.net_dvr_getlasterror ())); return;} SYSTEM.OUT.PRINTLN ("Serial number:" + new String (Lpdeviceinfo.sserialnumber)); System.out.println ("Number of Channels:" + (lPdeviceinfo.bychannum)); System.out.println ("Number of hard drives:" + (Lpdeviceinfo.bydisknum));} --------------------------------------------------------------------------the following for implementation and video display all code package Suigara.hardware.hc.htnet;import Static Suigara.hardware.hc.htnet.hcnetsdk.instance;import Java.awt.Color;import Java.awt.component;import Java.awt.dimension;import Java.awt.flowlayout;import Java.awt.Panel;import Java.awt.toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.event.mouseadapter;import Java.awt.event.mouseevent;import Java.io.file;import java.util.ArrayList; Import Java.util.list;import javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.joptionpane;import Javax.swing.jwindow;import Suigara.hardware.hc.htnet.hcnetsdk.net_dvr_clientinfo;import Suigara.hardware.hc.htnet.hcnetsdk.net_dvr_deviceinfo_v30;import Com.sun.jna.native;import Com.sun.jna.nativelong;import Com.sun.jna.platform.win32.windef.hwnd;public class Hcnetdemo {private static HCNetSDK hcnetsdk = instance;public static void Main (string[] args) {new Hcnetdemo ();} Private Nativelong userid;private JFrame JF = new JFrame ();p rivate List Handles = new ArrayList ();p ublic Hcnetdemo () {init ();} private void Init () {initui (); initsdk (); Login ("192.168.32.31", (short) 8000, "admin", "12345");} private void Login (string IP, short port, string username, string passwd) {if (UserID! = null && userid.longvalue ( ) >= 0) {hcnetsdk.net_dvr_logout (userid);} Net_dvr_deviceinfo_v30 lpdeviceinfo = new Net_dvr_deviceinfo_v30 ();//second Step UserID = HCNETSDK.NET_DVR_LOGIN_V30 (IP, Port, Username, passwd,lpdeviceinfo); if (Hcnetsdk.net_dvr_getlasterror ()! = 0) {userid = new Nativelong ( -1); ShowMessage (" Login failed: "+ geterrormessage (Hcnetsdk.net_dvr_getlasterror ())); return;} SYSTEM.OUT.PRINTLN ("Serial number:" + new String (Lpdeviceinfo.sserialnumber)); System.out.println ("Number of Channels:" + (Lpdeviceinfo.bychannum)); System.out.println ("Number of hard drives:" + (Lpdeviceinfo.bydisknum));} private void Initsdk () {Boolean initsuccess = Hcnetsdk.net_dvr_init (); if (!initsuccess) {showmessage ("Initialization failed HCNETSDK:" + GetErrorMessage (Instance.net_dvr_getlasterror ())); return;} Hcnetsdk.net_dvr_setconnecttime (2000, 1);} Private String geterrormessage (int errorCode) {return globalerror.valueof (errorCode). message (); private void Initui () {//Here with panel, do not switch to JPanel (the panel of the video and its parent panel can only use the AWT container,) panel parent = new Panel (); Parent.setpreferredsize (New Dimension (660, 530)); Jf.add (parent); Jf.setdefaultcloseoperation (jframe.exit_on_close );p Arent.setlayout (New FlowLayout ()), final panel panels[] = new Panel[4];for (int i = 0; i < panels.length; i++) {panel Cardpanel = new Panel (), Cardpanel.setpreferredsize (New Dimension ());p anels[i] = Cardpanel; Cardpanel.setbackground (New Color (0, 0, 0));p arent.add (cardpanel); final int channel = i + 1;cardpanel.addmouselistener ( New Mouseadapter () {public void mouseclicked (MouseEvent e) {panelrealplaymousepressed (E, Channel);}}); Button Final JButton start = new JButton ("Start Preview"), Start.setpreferredsize (New Dimension (100, 25)); JButton capture = new JButton (""); Capture.setpreferredsize (new Dimension);p Arent.add (start);p Arent.add ( capture); Jf.pack (); jf.setvisible (true); start.adDactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {if (Userid.longvalue () < 0) {showmessage ("Please login First"); return;} if (Handles.isempty ()) {for (int i = 0; i < panels.length; i++) {Panel cardpanel = panels[i]; HWND hwnd = Createhwndbycomponent (Cardpanel); Net_dvr_clientinfo lpclientinfo = new Net_dvr_clientinfo (); Lpclientinfo.hplaywnd = Hwnd;lpclientinfo.lchannel = new Nativelong (i + 1); lpclientinfo.smulticastip = ""; Lpclientinfo.llinkmode = new Nativelong (0);//Third step nativelong handle = HCNETSDK.NET_DVR_REALPLAY_V30 (userid, Lpclientinfo, NULL, NULL, TRUE); int net_dvr_getlasterror = Hcnetsdk.net_dvr_getlasterror (); if (net_dvr_getlasterror! = 0) {System.out.println ("error:" + geterrormessage (Net_dvr_getlasterror));} else {System.out.println ("handle:" + handle.longvalue ()); Handles.add (handle);}} if (!handles.isempty ()) {Start.settext ("Stop Preview");}} else {for (Nativelong handle:handles) {hcnetsdk.net_dvr_stoprealplay (handle);} Handles.clear (); Start.settext ("Start pre-(");}}); Capture.addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {String folder = "D : \\pic "; New File (folder). Mkdirs (); for (Nativelong handle:handles) {hcnetsdk.net_dvr_capturepicture (handle, Folder +) \ \ "+ handle +". jpg "); int error = Hcnetsdk.net_dvr_getlasterror (); Boolean hassuccess = false;if (Error! = 0) {System.out.println ( GetErrorMessage (Error)); ShowMessage ("Capture failure:" + geterrormessage (Error));} else {hassuccess = True;showmessage ("Capture succeeds, position in:" + folder);} if (hassuccess) {showmessage ("capture succeeded, position in:" + folder);}});} private void ShowMessage (String msg) {Joptionpane.showmessagedialog (JF, msg);} private void panelrealplaymousepressed (Java.awt.event.MouseEvent evt,int Channel) {//mouse click event is double-click if (Evt.getclickcount ( ) = = 2) {//new JWindow Full Screen preview final JWindow wnd = new JWindow ();//Get screen size dimension screensize = Toolkit.getdefaulttoolkit (). GE Tscreensize (); wnd.setsize (screensize); Wnd.setvisible (true), final HWND hwnd = new HWND (Native.getcomponentpointer ( WND)); Net_dvr_clientinfo lpclientinfo = new Net_dvr_clientinfo (); lpclientinfo.hplaywnd = Hwnd;lpclientinfo.lchannel = new Nativelong (channel); lpclientinfo.smulticastip = ""; lpclientinfo.llinkmode = new Nativelong (0); final Nativelong Lrealhandle = HCNETSDK.NET_DVR_REALPLAY_V30 (userid, lpclientinfo, NULL, NULL, TRUE);//JWindow Add double-click response function, stop preview when double-click, Exit full Screen Wnd.addmouselistener (new Java.awt.event.MouseAdapter () {public void mousepressed (Java.awt.event.MouseEvent evt) {if (evt.getclickcount () = = 2) {//Stop preview Hcnetsdk.net_dvr_stoprealplay (lrealhandle); Wnd.dispose ();}});}} Private HWND createhwndbycomponent (Component parent) {return new HWND (Native.getcomponentpointer (parent));}}

Based on the Marine Conway SDK javac/s

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.