When I run my codes, The image I want to display is much larger than the picture control – in fact, it takes up the entire dialog.
I wrote this :
#include "stdafx.h"
#include "BaslerCode.h"
#include <pylon/PylonIncludes.h>
#include <iostream>
#include "resource.h"
#include "CImageEventHandler.h"
void BaslerCode::OnImageGrabbed(CInstantCamera& camera, const CGrabResultPtr& ptrGrabResult)
{
if (ptrGrabResult->GrabSucceeded())
{
CImage img;
img.Create(imageRGB.GetWidth(), imageRGB.GetHeight(), 8);
imageRGB.GetWidth() * imageRGB.GetHeight());
errno_t memcpy_s(void *dest,size_t destSize,const void *src,size_t count);
CWnd* pPictureBox = AfxGetApp()->GetMainWnd();
CDC* pDC = pPictureBox->GetDC();
**img.StretchBlt(pDC->m_hDC,0,0,rect.Width(),rect.Height(),SRCCOPY);**
img.Draw(pDC->m_hDC, 0, 0);
pPictureBox->ReleaseDC(pDC);
}
}
6
You are using the wrong HWND. What you need is imageviewer.
CWnd* pPictureBox = AfxGetApp()->GetMainWnd();
and avoid redrawing. comment //img.Draw(pDC->m_hDC, 0, 0);
Also pay attention to length and width rect.Width(),rect.Height()
0