Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to modify the size of an image via the 'StretchBlt' function?

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);
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading