├── LICENSE ├── README.md ├── hk ├── MyCamera.cpp ├── MyCamera.h ├── qt_hik.cpp └── qt_hik.hpp ├── hkvision.pro ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── screenshots └── screenshots.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 timbrist 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hikvision-qt 2 | 海康威视工业相机 型号:MV-CA013-21UM sdk qt 二次开发 3 | 4 | 环境: 5 | Qt 5.13.0 MSVC2015 64bit 6 | 7 | 以实现: 8 | 海康威视提供的BasicDemo MFC 的大部分功能 9 | 查找,打开设备,关闭设备 10 | 开始停止采集 11 | 保存图片; 12 | ![ui](https://github.com/timbrist/hikvision-qt/blob/master/screenshots/screenshots.png) 13 | -------------------------------------------------------------------------------- /hk/MyCamera.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "MyCamera.h" 3 | #include 4 | 5 | CMyCamera::CMyCamera() 6 | { 7 | m_hDevHandle = NULL; 8 | } 9 | 10 | CMyCamera::~CMyCamera() 11 | { 12 | if (m_hDevHandle) 13 | { 14 | MV_CC_DestroyHandle(m_hDevHandle); 15 | m_hDevHandle = NULL; 16 | } 17 | } 18 | 19 | int CMyCamera::EnumDevices(MV_CC_DEVICE_INFO_LIST* pstDevList) 20 | { 21 | int nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, pstDevList); 22 | if (MV_OK != nRet) 23 | { 24 | return nRet; 25 | } 26 | 27 | return MV_OK; 28 | } 29 | 30 | // ch:打开设备 | en:Open Device 31 | int CMyCamera::Open(MV_CC_DEVICE_INFO* pstDeviceInfo) 32 | { 33 | if (NULL == pstDeviceInfo) 34 | { 35 | return MV_E_PARAMETER; 36 | } 37 | 38 | int nRet = MV_OK; 39 | if(m_hDevHandle == NULL) 40 | { 41 | nRet = MV_CC_CreateHandle(&m_hDevHandle, pstDeviceInfo); 42 | if (MV_OK != nRet) 43 | { 44 | return nRet; 45 | } 46 | } 47 | 48 | nRet = MV_CC_OpenDevice(m_hDevHandle); 49 | if (MV_OK != nRet) 50 | { 51 | MV_CC_DestroyHandle(m_hDevHandle); 52 | m_hDevHandle = NULL; 53 | 54 | return nRet; 55 | } 56 | 57 | return MV_OK; 58 | } 59 | 60 | 61 | // ch:关闭设备 | en:Close Device 62 | int CMyCamera::Close() 63 | { 64 | int nRet = MV_OK; 65 | 66 | if (NULL == m_hDevHandle) 67 | { 68 | return MV_E_PARAMETER; 69 | } 70 | 71 | MV_CC_CloseDevice(m_hDevHandle); 72 | nRet = MV_CC_DestroyHandle(m_hDevHandle); 73 | m_hDevHandle = NULL; 74 | 75 | return nRet; 76 | } 77 | 78 | 79 | // ch:开启抓图 | en:Start Grabbing 80 | int CMyCamera::StartGrabbing() 81 | { 82 | return MV_CC_StartGrabbing(m_hDevHandle); 83 | } 84 | 85 | 86 | // ch:停止抓图 | en:Stop Grabbing 87 | int CMyCamera::StopGrabbing() 88 | { 89 | return MV_CC_StopGrabbing(m_hDevHandle); 90 | } 91 | 92 | int CMyCamera::GetOneFrameTimeout(unsigned char* pData, unsigned int* pnDataLen, unsigned int nDataSize, MV_FRAME_OUT_INFO_EX* pFrameInfo, int nMsec) 93 | { 94 | if (NULL == pnDataLen) 95 | { 96 | return MV_E_PARAMETER; 97 | } 98 | 99 | int nRet = MV_OK; 100 | 101 | *pnDataLen = 0; 102 | 103 | nRet = MV_CC_GetOneFrameTimeout(m_hDevHandle, pData, nDataSize, pFrameInfo, nMsec); 104 | if (MV_OK != nRet) 105 | { 106 | return nRet; 107 | } 108 | 109 | *pnDataLen = pFrameInfo->nFrameLen; 110 | 111 | return nRet; 112 | } 113 | 114 | 115 | // ch:设置显示窗口句柄 | en:Set Display Window Handle 116 | int CMyCamera::Display(void* hWnd) 117 | { 118 | return MV_CC_Display(m_hDevHandle, hWnd); 119 | } 120 | 121 | 122 | int CMyCamera::SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam) 123 | { 124 | if (NULL == pstParam) 125 | { 126 | return MV_E_PARAMETER; 127 | } 128 | 129 | return MV_CC_SaveImageEx2(m_hDevHandle, pstParam); 130 | } 131 | 132 | // ch:注册图像数据回调 | en:Register Image Data CallBack 133 | int CMyCamera::RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, 134 | void* pUser),void* pUser) 135 | { 136 | return MV_CC_RegisterImageCallBackEx(m_hDevHandle, cbOutput, pUser); 137 | } 138 | 139 | 140 | // ch:注册消息异常回调 | en:Register Message Exception CallBack 141 | int CMyCamera::RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser),void* pUser) 142 | { 143 | return MV_CC_RegisterExceptionCallBack(m_hDevHandle, cbException, pUser); 144 | } 145 | 146 | 147 | // ch:获取Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 148 | // en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory 149 | int CMyCamera::GetIntValue(IN const char* strKey, OUT unsigned int *pnValue) 150 | { 151 | if (NULL == strKey || NULL == pnValue) 152 | { 153 | return MV_E_PARAMETER; 154 | } 155 | 156 | MVCC_INTVALUE stParam; 157 | memset(&stParam, 0, sizeof(MVCC_INTVALUE)); 158 | int nRet = MV_CC_GetIntValue(m_hDevHandle, strKey, &stParam); 159 | if (MV_OK != nRet) 160 | { 161 | return nRet; 162 | } 163 | 164 | *pnValue = stParam.nCurValue; 165 | 166 | return MV_OK; 167 | } 168 | 169 | 170 | // ch:设置Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 171 | // en:Set Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory 172 | int CMyCamera::SetIntValue(IN const char* strKey, IN unsigned int nValue) 173 | { 174 | if (NULL == strKey) 175 | { 176 | return MV_E_PARAMETER; 177 | } 178 | 179 | return MV_CC_SetIntValue(m_hDevHandle, strKey, nValue); 180 | } 181 | 182 | 183 | // ch:获取Float型参数,如 ExposureTime和Gain,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 184 | // en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory 185 | int CMyCamera::GetFloatValue(IN const char* strKey, OUT float *pfValue) 186 | { 187 | if (NULL == strKey || NULL == pfValue) 188 | { 189 | return MV_E_PARAMETER; 190 | } 191 | 192 | MVCC_FLOATVALUE stParam; 193 | memset(&stParam, 0, sizeof(MVCC_FLOATVALUE)); 194 | int nRet = MV_CC_GetFloatValue(m_hDevHandle, strKey, &stParam); 195 | if (MV_OK != nRet) 196 | { 197 | return nRet; 198 | } 199 | 200 | *pfValue = stParam.fCurValue; 201 | 202 | return MV_OK; 203 | } 204 | 205 | 206 | // ch:设置Float型参数,如 ExposureTime和Gain,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 207 | // en:Set Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory 208 | int CMyCamera::SetFloatValue(IN const char* strKey, IN float fValue) 209 | { 210 | if (NULL == strKey) 211 | { 212 | return MV_E_PARAMETER; 213 | } 214 | 215 | return MV_CC_SetFloatValue(m_hDevHandle, strKey, fValue); 216 | } 217 | 218 | 219 | // ch:获取Enum型参数,如 PixelFormat,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 220 | // en:Get Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory 221 | int CMyCamera::GetEnumValue(IN const char* strKey, OUT unsigned int *pnValue) 222 | { 223 | if (NULL == strKey || NULL == pnValue) 224 | { 225 | return MV_E_PARAMETER; 226 | } 227 | 228 | MVCC_ENUMVALUE stParam; 229 | memset(&stParam, 0, sizeof(MVCC_ENUMVALUE)); 230 | int nRet = MV_CC_GetEnumValue(m_hDevHandle, strKey, &stParam); 231 | if (MV_OK != nRet) 232 | { 233 | return nRet; 234 | } 235 | 236 | *pnValue = stParam.nCurValue; 237 | 238 | return MV_OK; 239 | } 240 | 241 | 242 | // ch:设置Enum型参数,如 PixelFormat,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 243 | // en:Set Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory 244 | int CMyCamera::SetEnumValue(IN const char* strKey, IN unsigned int nValue) 245 | { 246 | if (NULL == strKey) 247 | { 248 | return MV_E_PARAMETER; 249 | } 250 | 251 | return MV_CC_SetEnumValue(m_hDevHandle, strKey, nValue); 252 | } 253 | 254 | 255 | // ch:获取Bool型参数,如 ReverseX,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 256 | // en:Get Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory 257 | int CMyCamera::GetBoolValue(IN const char* strKey, OUT bool *pbValue) 258 | { 259 | if (NULL == strKey || NULL == pbValue) 260 | { 261 | return MV_E_PARAMETER; 262 | } 263 | 264 | return MV_CC_GetBoolValue(m_hDevHandle, strKey, pbValue); 265 | } 266 | 267 | 268 | // ch:设置Bool型参数,如 ReverseX,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 269 | // en:Set Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory 270 | int CMyCamera::SetBoolValue(IN const char* strKey, IN bool bValue) 271 | { 272 | if (NULL == strKey) 273 | { 274 | return MV_E_PARAMETER; 275 | } 276 | 277 | return MV_CC_SetBoolValue(m_hDevHandle, strKey, bValue); 278 | } 279 | 280 | 281 | // ch:获取String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave 282 | // en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory 283 | int CMyCamera::GetStringValue(IN const char* strKey, IN OUT char* strValue, IN unsigned int nSize) 284 | { 285 | if (NULL == strKey || NULL == strValue) 286 | { 287 | return MV_E_PARAMETER; 288 | } 289 | 290 | MVCC_STRINGVALUE stParam; 291 | memset(&stParam, 0, sizeof(MVCC_STRINGVALUE)); 292 | int nRet = MV_CC_GetStringValue(m_hDevHandle, strKey, &stParam); 293 | if (MV_OK != nRet) 294 | { 295 | return nRet; 296 | } 297 | 298 | strcpy_s(strValue, nSize, stParam.chCurValue); 299 | 300 | return MV_OK; 301 | } 302 | 303 | 304 | // ch:设置String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave 305 | // en:Set String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory 306 | int CMyCamera::SetStringValue(IN const char* strKey, IN const char* strValue) 307 | { 308 | if (NULL == strKey) 309 | { 310 | return MV_E_PARAMETER; 311 | } 312 | 313 | return MV_CC_SetStringValue(m_hDevHandle, strKey, strValue); 314 | } 315 | 316 | 317 | // ch:执行一次Command型命令,如 UserSetSave,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 318 | // en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory 319 | int CMyCamera::CommandExecute(IN const char* strKey) 320 | { 321 | if (NULL == strKey) 322 | { 323 | return MV_E_PARAMETER; 324 | } 325 | 326 | return MV_CC_SetCommandValue(m_hDevHandle, strKey); 327 | } 328 | 329 | int CMyCamera::GetOptimalPacketSize() 330 | { 331 | return MV_CC_GetOptimalPacketSize(m_hDevHandle); 332 | } 333 | 334 | int CMyCamera::GetAllMatchInfo(OUT unsigned int *nLostFrame, OUT unsigned int *nFrameCount) 335 | { 336 | MV_CC_DEVICE_INFO stDevInfo = {0}; 337 | int nRet = MV_CC_GetDeviceInfo(m_hDevHandle, &stDevInfo); //该接口u3暂不支持,用此方式来判断u3还是GigE 338 | if (MV_E_SUPPORT == nRet) 339 | { 340 | stDevInfo.nTLayerType = MV_USB_DEVICE; 341 | } 342 | 343 | if (MV_GIGE_DEVICE == stDevInfo.nTLayerType) 344 | { 345 | MV_ALL_MATCH_INFO struMatchInfo = {0}; 346 | MV_MATCH_INFO_NET_DETECT stMatchInfoNetDetect; 347 | struMatchInfo.pInfo = &stMatchInfoNetDetect; 348 | 349 | struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT; // ch:网络流量和丢包信息 | en:Net flow and lsot packet information 350 | memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT)); 351 | struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT); 352 | 353 | nRet = MV_CC_GetAllMatchInfo(m_hDevHandle, &struMatchInfo); 354 | if (MV_OK != nRet) 355 | { 356 | return nRet; 357 | } 358 | 359 | MV_MATCH_INFO_NET_DETECT *pInfo = (MV_MATCH_INFO_NET_DETECT*)struMatchInfo.pInfo; 360 | *nFrameCount = pInfo->nNetRecvFrameCount; 361 | *nLostFrame = stMatchInfoNetDetect.nLostFrameCount; 362 | } 363 | else if (MV_USB_DEVICE == stDevInfo.nTLayerType) 364 | { 365 | MV_ALL_MATCH_INFO struMatchInfo = {0}; 366 | MV_MATCH_INFO_USB_DETECT stMatchInfoNetDetect; 367 | struMatchInfo.pInfo = &stMatchInfoNetDetect; 368 | 369 | struMatchInfo.nType = MV_MATCH_TYPE_USB_DETECT; // ch:网络流量和丢包信息 | en:Net flow and lsot packet information 370 | memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_USB_DETECT)); 371 | struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_USB_DETECT); 372 | 373 | nRet = MV_CC_GetAllMatchInfo(m_hDevHandle, &struMatchInfo); 374 | if (MV_OK != nRet) 375 | { 376 | return nRet; 377 | } 378 | 379 | MV_MATCH_INFO_NET_DETECT *pInfo = (MV_MATCH_INFO_NET_DETECT*)struMatchInfo.pInfo; 380 | *nFrameCount = pInfo->nNetRecvFrameCount; 381 | *nLostFrame = stMatchInfoNetDetect.nErrorFrameCount; 382 | } 383 | 384 | return MV_OK; 385 | } 386 | 387 | 388 | -------------------------------------------------------------------------------- /hk/MyCamera.h: -------------------------------------------------------------------------------- 1 | /************************************************************************/ 2 | /* 以C++接口为基础,对常用函数进行二次封装,方便用户使用 */ 3 | /************************************************************************/ 4 | 5 | #ifndef _MY_CAMERA_H_ 6 | #define _MY_CAMERA_H_ 7 | 8 | #include 9 | #include "MvCameraControl.h" 10 | 11 | class CMyCamera 12 | { 13 | public: 14 | CMyCamera(); 15 | ~CMyCamera(); 16 | 17 | static int EnumDevices(MV_CC_DEVICE_INFO_LIST* pstDevList); 18 | 19 | // ch:打开设备 | en:Open Device 20 | int Open(MV_CC_DEVICE_INFO* pstDeviceInfo); 21 | 22 | // ch:关闭设备 | en:Close Device 23 | int Close(); 24 | 25 | // ch:开启抓图 | en:Start Grabbing 26 | int StartGrabbing(); 27 | 28 | // ch:停止抓图 | en:Stop Grabbing 29 | int StopGrabbing(); 30 | 31 | // ch:主动获取一帧图像数据 | en:Get one frame initiatively 32 | int GetOneFrameTimeout(unsigned char* pData, unsigned int* pnDataLen, unsigned int nDataSize, MV_FRAME_OUT_INFO_EX* pFrameInfo, int nMsec); 33 | 34 | // ch:设置显示窗口句柄 | en:Set Display Window Handle 35 | int Display(void* hWnd); 36 | 37 | // ch:保存图片 | en:save image 38 | int SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam); 39 | 40 | // ch:注册图像数据回调 | en:Register Image Data CallBack 41 | int RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), 42 | void* pUser); 43 | 44 | // ch:注册消息异常回调 | en:Register Message Exception CallBack 45 | int RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser), 46 | void* pUser); 47 | 48 | // ch:获取Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 49 | // en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory 50 | int GetIntValue(IN const char* strKey, OUT unsigned int *pnValue); 51 | int SetIntValue(IN const char* strKey, IN unsigned int nValue); 52 | 53 | // ch:获取Float型参数,如 ExposureTime和Gain,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 54 | // en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory 55 | int GetFloatValue(IN const char* strKey, OUT float *pfValue); 56 | int SetFloatValue(IN const char* strKey, IN float fValue); 57 | 58 | // ch:获取Enum型参数,如 PixelFormat,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 59 | // en:Get Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory 60 | int GetEnumValue(IN const char* strKey, OUT unsigned int *pnValue); 61 | int SetEnumValue(IN const char* strKey, IN unsigned int nValue); 62 | 63 | // ch:获取Bool型参数,如 ReverseX,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 64 | // en:Get Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory 65 | int GetBoolValue(IN const char* strKey, OUT bool *pbValue); 66 | int SetBoolValue(IN const char* strKey, IN bool bValue); 67 | 68 | // ch:获取String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave 69 | // en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory 70 | int GetStringValue(IN const char* strKey, IN OUT char* strValue, IN unsigned int nSize); 71 | int SetStringValue(IN const char* strKey, IN const char * strValue); 72 | 73 | // ch:执行一次Command型命令,如 UserSetSave,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件 74 | // en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory 75 | int CommandExecute(IN const char* strKey); 76 | 77 | // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera) 78 | int GetOptimalPacketSize(); 79 | 80 | // 获取统计参数 81 | int GetAllMatchInfo(OUT unsigned int *nLostFrame, OUT unsigned int *nFrameCount); 82 | 83 | private: 84 | 85 | void* m_hDevHandle; 86 | 87 | public: 88 | unsigned char* m_pBufForSaveImage; // 用于保存图像的缓存 89 | unsigned int m_nBufSizeForSaveImage; 90 | 91 | unsigned char* m_pBufForDriver; // 用于从驱动获取图像的缓存 92 | unsigned int m_nBufSizeForDriver; 93 | 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /hk/qt_hik.cpp: -------------------------------------------------------------------------------- 1 | #include "hk/qt_hik.hpp" 2 | #include 3 | 4 | #define IMAGE_NAME_LEN 64 5 | 6 | using namespace QtHik; 7 | using namespace std; 8 | HikWindow::HikWindow() 9 | { 10 | //一定要初始化, 私有变量未初始化不是空指针。 11 | //不初始化导致莫名其妙的bug 12 | //连判断都进不去 13 | 14 | //指针一定要初始化 15 | m_pBufForDriver = nullptr; 16 | m_pBufForSaveImage = nullptr; 17 | m_pcMyCamera = nullptr; 18 | m_hwndDisplay = nullptr; 19 | 20 | m_nBufSizeForDriver = 0; 21 | m_bOpenDevice =FALSE; 22 | m_bStartGrabbing = FALSE; 23 | m_nTriggerMode = 0; 24 | m_nBufSizeForSaveImage = 0; 25 | 26 | } 27 | HikWindow::~HikWindow() 28 | { 29 | //回收的好习惯 30 | delete m_pBufForDriver; 31 | delete m_pBufForSaveImage; 32 | delete m_pcMyCamera; 33 | } 34 | int HikWindow::EnumDevices(vector< QString> &QUserNames) 35 | { 36 | // ch:设备信息列表结构体变量,用来存储设备列表 37 | // ch:初始化设备信息列表 38 | memset(&this->m_stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST)); 39 | int nRet = CMyCamera::EnumDevices(&this->m_stDevList); 40 | if(nRet != MV_OK) 41 | { 42 | return -1; 43 | } 44 | for(size_t i = 0; i < this->m_stDevList.nDeviceNum; i++) 45 | { 46 | //设备信息 47 | MV_CC_DEVICE_INFO *pDeviceInfo = this->m_stDevList.pDeviceInfo[i]; 48 | if(pDeviceInfo == nullptr) 49 | { 50 | continue; 51 | } 52 | unsigned char *pUserName = pDeviceInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName; 53 | string pUserName2 = reinterpret_cast(pUserName); 54 | QUserNames.push_back( QString::fromStdString(pUserName2) ); 55 | } 56 | if(this->m_stDevList.nDeviceNum == 0) 57 | { 58 | //throw "No device" ; 59 | return -1; 60 | } 61 | return MV_OK; 62 | } 63 | 64 | int HikWindow::OpenDevice(int &nIndex) 65 | { 66 | if(m_bOpenDevice == TRUE) 67 | return -1; 68 | 69 | if( (nIndex < 0) || (nIndex >= MV_MAX_DEVICE_NUM)) 70 | { 71 | //throw "Please select device "; 72 | return -1; 73 | } 74 | if(this->m_stDevList.pDeviceInfo[nIndex] == nullptr) 75 | { 76 | //throw "Open Device Failed"; 77 | return -1; 78 | } 79 | 80 | this->m_pcMyCamera = new CMyCamera; 81 | if(this->m_pcMyCamera == nullptr) 82 | { 83 | //throw "Initailized Failed"; 84 | return -1; 85 | } 86 | int nRet = m_pcMyCamera->Open(this->m_stDevList.pDeviceInfo[nIndex]); 87 | if(nRet != MV_OK) 88 | { 89 | delete this->m_pcMyCamera; 90 | this->m_pcMyCamera = nullptr; 91 | return nRet; 92 | } 93 | m_bOpenDevice = TRUE; 94 | return MV_OK; 95 | } 96 | 97 | int HikWindow::CloseDevice() 98 | { 99 | if(m_pcMyCamera != nullptr) 100 | { 101 | m_pcMyCamera->Close(); 102 | delete m_pcMyCamera; 103 | m_pcMyCamera = nullptr; 104 | } 105 | m_bOpenDevice = FALSE; 106 | m_bStartGrabbing = FALSE; 107 | /* 108 | if(m_pBufForDriver != nullptr) 109 | { 110 | free(m_pBufForDriver); 111 | //m_pBufForDriver = nullptr; 112 | } 113 | //m_nBufSizeForDriver = 0; 114 | if(m_pBufForSaveImage != nullptr) 115 | { 116 | free(m_pBufForSaveImage); 117 | //m_pBufForSaveImage = nullptr; 118 | 119 | } 120 | //m_nBufSizeForSaveImage = 0; 121 | */ 122 | return MV_OK; 123 | } 124 | 125 | int HikWindow::SetTriggerMode(unsigned int trigger_mode) 126 | { 127 | if(trigger_mode == 0) 128 | this->m_nTriggerMode = MV_TRIGGER_MODE_OFF; 129 | else { 130 | this->m_nTriggerMode = MV_TRIGGER_MODE_ON; 131 | } 132 | int nRet = m_pcMyCamera->SetEnumValue("TriggerMode", this->m_nTriggerMode); 133 | if(nRet != MV_OK) 134 | return nRet; 135 | return MV_OK; 136 | } 137 | 138 | int HikWindow::StartGrabbing(HWND MainWndID) 139 | { 140 | //开始采集 141 | if(m_bOpenDevice == FALSE || m_bStartGrabbing == TRUE) 142 | { 143 | return -1; 144 | } 145 | int nRet = -1; 146 | if(m_pcMyCamera != nullptr) 147 | { 148 | nRet = m_pcMyCamera->StartGrabbing(); 149 | //m_pcMyCamera->m_hDevHandle = MainWndID; 150 | this->m_hwndDisplay = MainWndID; 151 | if(nRet == MV_OK) 152 | { 153 | nRet = m_pcMyCamera->Display(m_hwndDisplay); 154 | } 155 | } 156 | else { 157 | return -1; 158 | } 159 | if(nRet != MV_OK) 160 | return -1; 161 | if(nRet != MV_OK) 162 | { 163 | //QMessageBox::information(this,"hint","failed in get payloadsize"); 164 | return -1; 165 | } 166 | m_bStartGrabbing = TRUE; 167 | return nRet; 168 | } 169 | 170 | int HikWindow::StopGrabbing() 171 | { 172 | if(m_bOpenDevice == FALSE || m_bStartGrabbing == FALSE) 173 | { 174 | return -1; 175 | } 176 | int nRet = -1; 177 | if(m_pcMyCamera != nullptr) 178 | { 179 | nRet = m_pcMyCamera->StopGrabbing(); 180 | } 181 | else { 182 | return -1; 183 | } 184 | m_bStartGrabbing = FALSE; 185 | return nRet; 186 | } 187 | 188 | int HikWindow::SaveBmp() 189 | { 190 | if(m_bStartGrabbing == FALSE) 191 | { 192 | return -1; 193 | } 194 | unsigned int nRecvBufSize=0; 195 | int nRet = MV_OK; 196 | if(m_pBufForDriver == nullptr) 197 | { 198 | nRet = m_pcMyCamera->GetIntValue("PayloadSize",&nRecvBufSize); 199 | if(nRet != MV_OK) 200 | { 201 | return nRet; 202 | } 203 | m_nBufSizeForDriver = nRecvBufSize; 204 | m_pBufForDriver = static_cast( 205 | malloc(m_nBufSizeForDriver)); 206 | if(m_pBufForDriver == nullptr) 207 | { 208 | return nRet; 209 | } 210 | } 211 | 212 | MV_FRAME_OUT_INFO_EX stImageInfo = {0}; 213 | memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX)); 214 | unsigned int nDataSize = nRecvBufSize; 215 | unsigned int nImageNum = 1; 216 | unsigned int nDataLen = 0; 217 | 218 | //========== 219 | while(nImageNum) 220 | { 221 | //一定要初始化, 私有变量, 不然各种bug 222 | nRet = m_pcMyCamera->GetOneFrameTimeout(m_pBufForDriver, 223 | &nDataLen, 224 | m_nBufSizeForDriver, 225 | &stImageInfo, 226 | 10000000); 227 | if(nRet == MV_OK) 228 | { 229 | nImageNum--; 230 | if(m_pBufForSaveImage == nullptr) 231 | { 232 | m_nBufSizeForSaveImage = stImageInfo.nWidth * 233 | stImageInfo.nHeight * 234 | 3 + 235 | 2048; 236 | 237 | m_pBufForSaveImage = static_cast( 238 | malloc(m_nBufSizeForSaveImage)); 239 | 240 | if(m_pBufForSaveImage == nullptr) 241 | { 242 | return -1; 243 | } 244 | } 245 | // ch:设置对应的相机参数 | en:Set camera parameter 246 | MV_SAVE_IMAGE_PARAM_EX stParam = {0}; 247 | stParam.enImageType = MV_Image_Bmp; // ch:需要保存的图像类型 | en:Image format to save 248 | stParam.enPixelType = stImageInfo.enPixelType; // ch:相机对应的像素格式 | en:Camera pixel type 249 | stParam.nWidth = stImageInfo.nWidth; // ch:相机对应的宽 | en:Width 250 | stParam.nHeight = stImageInfo.nHeight; // ch:相机对应的高 | en:Height 251 | stParam.nDataLen = stImageInfo.nFrameLen; 252 | stParam.pData = m_pBufForDriver; 253 | stParam.pImageBuffer = m_pBufForSaveImage; 254 | stParam.nBufferSize = m_nBufSizeForSaveImage; // ch:存储节点的大小 | en:Buffer node size 255 | stParam.nJpgQuality = 80; // ch:jpg编码,仅在保存Jpg图像时有效。保存BMP时SDK内忽略该参数 256 | //保存图片这里会返回错误 257 | nRet = m_pcMyCamera->SaveImage(&stParam); 258 | 259 | if(nRet != MV_OK) 260 | { 261 | return -1; 262 | } 263 | 264 | 265 | char chImageName[IMAGE_NAME_LEN] = {0}; 266 | sprintf_s(chImageName, 267 | IMAGE_NAME_LEN, 268 | "Image_w%d_h%d_fn%03d.bmp", 269 | stImageInfo.nWidth, 270 | stImageInfo.nHeight, 271 | stImageInfo.nFrameNum); 272 | FILE *fp = fopen(chImageName, "wb"); 273 | fwrite(m_pBufForSaveImage, 1, stParam.nImageLen, fp); 274 | fclose(fp); 275 | } 276 | else { 277 | return -1; 278 | } 279 | }//while 280 | return nRet; 281 | } 282 | -------------------------------------------------------------------------------- /hk/qt_hik.hpp: -------------------------------------------------------------------------------- 1 | #ifndef QT_HIK_HPP 2 | #define QT_HIK_HPP 3 | //hikvision sdk 在qt上显示的内容。 4 | //以Qt MainWindow接口为基础,对常用函数进行三次次封装,方便qt用户使用 5 | 6 | #include "hk/MyCamera.h" 7 | #include "Windows.h"//HWND 8 | #include 9 | #include 10 | #include 11 | 12 | namespace QtHik { 13 | class HikWindow 14 | { 15 | public: 16 | HikWindow(); 17 | ~HikWindow(); 18 | //海康威视的接口及变量操作 19 | public: 20 | //列举出说有设备并返回设备名字 21 | //私有变量 m_stDevList会保存设备信息 22 | int EnumDevices(std::vector &QUserNames); 23 | 24 | //输入需要打开设备的编号 25 | //需要EnumDevice函数得到 m_stDevList内容 26 | int OpenDevice(int &nIndex); 27 | 28 | //对私有变量进行回收 29 | int CloseDevice(); 30 | 31 | //设置采集模式 //触发模式设置 32 | //对私有变量m_nTriggerMode 进行 0 或 1 赋值。 33 | int SetTriggerMode(unsigned int trigger_mode); 34 | 35 | //开始采集 36 | //用引用居然莫名其妙卡死 37 | int StartGrabbing(HWND MainWndId); 38 | 39 | //关闭采集 40 | int StopGrabbing(); 41 | 42 | //保存Bmp图片 43 | int SaveBmp(); 44 | 45 | 46 | 47 | private: 48 | unsigned char* m_pBufForDriver; // ch:用于从驱动获取图像的缓存 49 | unsigned int m_nBufSizeForDriver; 50 | 51 | /*ch:状态 | en:Status*/ 52 | BOOL m_bOpenDevice; // ch:是否打开设备 53 | BOOL m_bStartGrabbing; // ch:是否开始抓图 54 | unsigned int m_nTriggerMode; // ch:触发模式 55 | int m_nTriggerSource; // ch:触发源 56 | MV_SAVE_IAMGE_TYPE m_nSaveImageType; // ch:保存图像格式 57 | 58 | /*ch:设备相关 | en:Device Related*/ 59 | CMyCamera* m_pcMyCamera; // ch:CMyCamera封装了常用接口 60 | HWND m_hwndDisplay; // ch:显示句柄 61 | MV_CC_DEVICE_INFO_LIST m_stDevList; // ch:设备信息列表结构体变量,用来存储设备列表 62 | unsigned char* m_pBufForSaveImage; // ch:用于保存图像的缓存 | en:Buffer to save image 63 | unsigned int m_nBufSizeForSaveImage; 64 | 65 | 66 | 67 | }; 68 | 69 | } 70 | 71 | #endif // QT_HIK_HPP 72 | -------------------------------------------------------------------------------- /hkvision.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-08-06T14:50:52 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = hkvision 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | hk/MyCamera.cpp \ 29 | hk/qt_hik.cpp \ 30 | main.cpp \ 31 | mainwindow.cpp 32 | 33 | HEADERS += \ 34 | hk/MyCamera.h \ 35 | hk/qt_hik.hpp \ 36 | mainwindow.h 37 | 38 | FORMS += \ 39 | mainwindow.ui 40 | 41 | # Default rules for deployment. 42 | qnx: target.path = /tmp/$${TARGET}/bin 43 | else: unix:!android: target.path = /opt/$${TARGET}/bin 44 | !isEmpty(target.path): INSTALLS += target 45 | 46 | win32: LIBS += -L$$PWD/hk/ -lMvCameraControl 47 | 48 | INCLUDEPATH += $$PWD/hk/includes 49 | DEPENDPATH += $$PWD/hk/includes 50 | 51 | win32:!win32-g++: PRE_TARGETDEPS += $$PWD/hk/MvCameraControl.lib 52 | 53 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | MainWindow w; 10 | w.show(); 11 | 12 | //graphicsView 13 | 14 | 15 | 16 | return a.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include //设备名字显示 4 | #include //多个设备数组 5 | #include 6 | using namespace std; 7 | MainWindow::MainWindow(QWidget *parent) : 8 | QMainWindow(parent), 9 | ui(new Ui::MainWindow) 10 | { 11 | 12 | ui->setupUi(this); 13 | } 14 | 15 | MainWindow::~MainWindow() 16 | { 17 | delete ui; 18 | } 19 | //按钮与按钮之间的逻辑 20 | 21 | //查找设备按钮会与combobox, open button, displayLable控件交互 22 | void MainWindow::on_EnumButton_clicked() 23 | { 24 | ui->DisplayLabel->setStyleSheet("border:1px solid black;"); 25 | vector< QString > QUserNames; 26 | if( hik.EnumDevices(QUserNames) != MV_OK) 27 | { 28 | QMessageBox::information(this,"异常","查找设备失败"); 29 | return; 30 | } 31 | for(size_t i = 0; i < QUserNames.size(); i++) 32 | { 33 | ui->comboBox->addItem(QUserNames[i]); 34 | } 35 | ui->OpenButton->setDisabled(false); 36 | 37 | } 38 | 39 | //打开设备, 读取当前的combobox 40 | //控件与关闭设备交互 41 | void MainWindow::on_OpenButton_clicked() 42 | { 43 | 44 | int nIndex = ui->comboBox->currentIndex(); 45 | if ( hik.OpenDevice(nIndex) != MV_OK ) 46 | { 47 | QMessageBox::information(this,"异常","打开设备失败"); 48 | return; 49 | } 50 | ui->OpenButton->setDisabled(true); 51 | ui->CloseButton->setDisabled(false); 52 | ui->StartGrabbingButton->setDisabled(false); 53 | } 54 | 55 | //关闭设备按钮, 56 | //与open button交互 57 | void MainWindow::on_CloseButton_clicked() 58 | { 59 | if(hik.CloseDevice() != MV_OK) 60 | { 61 | QMessageBox::information(this,"异常","关闭设备失败"); 62 | return; 63 | } 64 | ui->OpenButton->setDisabled(false); 65 | ui->CloseButton->setDisabled(false); 66 | } 67 | 68 | //开始采集 69 | void MainWindow::on_StartGrabbingButton_clicked() 70 | { 71 | HWND MainWndID = (HWND)ui->DisplayLabel->winId(); 72 | if( hik.StartGrabbing(MainWndID) != MV_OK) 73 | { 74 | QMessageBox::information(this,"异常","采集设备失败"); 75 | return; 76 | } 77 | ui->StartGrabbingButton->setDisabled(true); 78 | ui->StopGrabbingButton->setDisabled(false); 79 | ui->SaveBmpButton->setDisabled(false); 80 | ui->SaveJpgButton->setDisabled(false); 81 | } 82 | 83 | 84 | void MainWindow::on_StopGrabbingButton_clicked() 85 | { 86 | if( hik.StopGrabbing() != MV_OK) 87 | { 88 | QMessageBox::information(this,"异常","关闭采集失败"); 89 | return; 90 | } 91 | ui->StartGrabbingButton->setDisabled(false); 92 | ui->StopGrabbingButton->setDisabled(true); 93 | } 94 | 95 | void MainWindow::on_SaveBmpButton_clicked() 96 | { 97 | if( hik.SaveBmp() != MV_OK) 98 | { 99 | QMessageBox::information(this,"异常","保存bmp失败"); 100 | return; 101 | } 102 | else { 103 | QMessageBox::information(this,"成功","保存图片成功"); 104 | } 105 | } 106 | 107 | //按下触发采集 108 | void MainWindow::on_HardwareRadioButton_clicked() 109 | { 110 | if( hik.SetTriggerMode(1) != MV_OK) 111 | { 112 | QMessageBox::information(this, "异常", "触发采集失败"); 113 | } 114 | } 115 | 116 | //连续采集 117 | void MainWindow::on_ContinuesRadioButton_clicked() 118 | { 119 | if( hik.SetTriggerMode(0) != MV_OK) 120 | { 121 | QMessageBox::information(this, "异常", "触发采集失败"); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | 11 | class MainWindow : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | private slots: 19 | void on_EnumButton_clicked(); 20 | 21 | void on_OpenButton_clicked(); 22 | 23 | void on_CloseButton_clicked(); 24 | 25 | void on_StartGrabbingButton_clicked(); 26 | 27 | void on_StopGrabbingButton_clicked(); 28 | 29 | void on_SaveBmpButton_clicked(); 30 | 31 | void on_HardwareRadioButton_clicked(); 32 | 33 | void on_ContinuesRadioButton_clicked(); 34 | 35 | private: 36 | Ui::MainWindow *ui; 37 | 38 | //海康威视接口对象 39 | private: 40 | QtHik::HikWindow hik; 41 | 42 | 43 | }; 44 | 45 | #endif // MAINWINDOW_H 46 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 803 10 | 556 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 50 22 | 581 23 | 431 24 | 25 | 26 | 27 | border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0); 28 | 29 | 30 | 31 | 32 | 33 | true 34 | 35 | 36 | 1 37 | 38 | 39 | 40 | 41 | 42 | 0 43 | 10 44 | 791 45 | 22 46 | 47 | 48 | 49 | 50 | 51 | 52 | 620 53 | 50 54 | 171 55 | 20 56 | 57 | 58 | 59 | 查找设备 60 | 61 | 62 | 63 | 64 | false 65 | 66 | 67 | 68 | 620 69 | 80 70 | 80 71 | 20 72 | 73 | 74 | 75 | 打开设备 76 | 77 | 78 | 79 | 80 | false 81 | 82 | 83 | 84 | 710 85 | 80 86 | 80 87 | 20 88 | 89 | 90 | 91 | 关闭设备 92 | 93 | 94 | 95 | 96 | true 97 | 98 | 99 | 100 | 620 101 | 110 102 | 81 103 | 18 104 | 105 | 106 | 107 | 连续模式 108 | 109 | 110 | true 111 | 112 | 113 | 114 | 115 | 116 | 710 117 | 110 118 | 81 119 | 18 120 | 121 | 122 | 123 | 触发模式 124 | 125 | 126 | 127 | 128 | false 129 | 130 | 131 | 132 | 620 133 | 140 134 | 80 135 | 20 136 | 137 | 138 | 139 | 开始采集 140 | 141 | 142 | 143 | 144 | false 145 | 146 | 147 | 148 | 710 149 | 140 150 | 80 151 | 20 152 | 153 | 154 | 155 | 停止采集 156 | 157 | 158 | 159 | 160 | false 161 | 162 | 163 | 164 | 620 165 | 270 166 | 81 167 | 20 168 | 169 | 170 | 171 | 保存BMP 172 | 173 | 174 | 175 | 176 | 177 | 680 178 | 310 179 | 113 180 | 20 181 | 182 | 183 | 184 | 185 | 186 | 187 | 620 188 | 310 189 | 51 190 | 16 191 | 192 | 193 | 194 | 曝光 195 | 196 | 197 | 198 | 199 | 200 | 680 201 | 340 202 | 113 203 | 20 204 | 205 | 206 | 207 | 208 | 209 | 210 | 620 211 | 340 212 | 54 213 | 12 214 | 215 | 216 | 217 | 增益 218 | 219 | 220 | 221 | 222 | 223 | 620 224 | 370 225 | 54 226 | 12 227 | 228 | 229 | 230 | 帧率 231 | 232 | 233 | 234 | 235 | 236 | 680 237 | 370 238 | 113 239 | 20 240 | 241 | 242 | 243 | 244 | 245 | false 246 | 247 | 248 | 249 | 620 250 | 410 251 | 80 252 | 20 253 | 254 | 255 | 256 | 参数获取 257 | 258 | 259 | 260 | 261 | false 262 | 263 | 264 | 265 | 710 266 | 410 267 | 80 268 | 20 269 | 270 | 271 | 272 | 设置参数 273 | 274 | 275 | 276 | 277 | false 278 | 279 | 280 | 281 | 710 282 | 270 283 | 80 284 | 20 285 | 286 | 287 | 288 | 保存jpg 289 | 290 | 291 | 292 | 293 | 294 | 620 295 | 170 296 | 73 297 | 18 298 | 299 | 300 | 301 | 软触发 302 | 303 | 304 | 305 | 306 | false 307 | 308 | 309 | 310 | 710 311 | 170 312 | 80 313 | 20 314 | 315 | 316 | 317 | 软触发一次 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | -------------------------------------------------------------------------------- /screenshots/screenshots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timbrist/hikvision-qt/9f95a27830fc36180451e7b3eef0a3be0206c0db/screenshots/screenshots.png --------------------------------------------------------------------------------