opencv-hbitmap\u5728\u5185\u5b58\u4e2d\u76f4\u63a5\u8f6cjgp\u683c\u5f0f-bmp\u8f6cjpg<\/strong><\/p>\n
\r\nIplImage* CMainFrame::Bitmap2IplImage(HANDLE hBitmap)\r\n{\r\n\tBITMAP bmp; \/\/ \u5f97\u5230\u4f4d\u56fe\u5bf9\u8c61\r\n\tint nPicSize;\r\n\tnPicSize = sizeof(BITMAP);\r\n\tGetObject(hBitmap, sizeof(BITMAP), &bmp);\r\n\r\n\tint depth,nChannels;\r\n\tif(bmp.bmBitsPixel == 1)\/\/\u5f97\u5230\u56fe\u50cf\u6df1\u5ea6\u548c\u901a\u9053\u6570\r\n\t{\r\n\t\tdepth=IPL_DEPTH_1U;\r\n\t\tnChannels=1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tdepth=IPL_DEPTH_8U;\r\n\t\tnChannels=bmp.bmBitsPixel\/8;\r\n\t}\r\n\tlong\tnBuffer = bmp.bmHeight*bmp.bmWidth*nChannels;\r\n\tIplImage* pImg = cvCreateImage(cvSize(bmp.bmWidth,bmp.bmHeight), depth, nChannels); \/\/\u521b\u5efa\u56fe\u50cf\r\n\tBYTE *pBuffer = new BYTE[nBuffer]; \/\/\u521b\u5efa\u7f13\u51b2\u533a\r\n\t\/\/GetBitmapBits(hBmp, bmp.bmHeight*bmp.bmWidth*nChannels, pBuffer); \/\/\u5c06\u4f4d\u56fe\u4fe1\u606f\u590d\u5236\u5230\u7f13\u51b2\u533a\r\n\tGetBitmapBits((HBITMAP)hBitmap, nBuffer, pBuffer); \/\/\u5c06\u4f4d\u56fe\u4fe1\u606f\u590d\u5236\u5230\u7f13\u51b2\u533a\r\n\tmemcpy(pImg->imageData, pBuffer, nBuffer);\/\/\u5c06\u7f13\u51b2\u533a\u4fe1\u606f\u590d\u5236\u7ed9IplImage\r\n\tdelete [] pBuffer;\/\/\u9632\u6b62\u5185\u5b58\u6cc4\u9732\r\n\t\/\/cvSaveImage(\"kkk.jpg\",pImg,0);\r\nreturn pImg;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"opencv-hbitmap\u5728\u5185\u5b58\u4e2d\u76f4\u63a5\u8f6cjgp\u683c\u5f0f-bmp\u8f6cjpg IplImage* CMainFrame::Bitmap2IplImage(HANDLE hBitmap) { BITMAP bmp; \/\/ \u5f97\u5230\u4f4d\u56fe\u5bf9\u8c61 int nPicSize; nPicSize = sizeof(BITMAP); GetObject(hBitmap, sizeof(BITMAP), &bmp); int depth,nChannels; if(bmp.bmBitsPixel == 1)\/\/\u5f97\u5230\u56fe\u50cf\u6df1\u5ea6\u548c\u901a\u9053\u6570 { depth=IPL_DEPTH_1U; nChannels=1; } else { de<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,219,9,150],"tags":[],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1489"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1489"}],"version-history":[{"count":1,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1489\/revisions"}],"predecessor-version":[{"id":1490,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1489\/revisions\/1490"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1489"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}