Ask Your Question

Poky's profile - activity

2019-09-02 10:45:37 -0600 received badge  Popular Question (source)
2015-07-03 00:27:46 -0600 received badge  Critic (source)
2015-07-03 00:27:39 -0600 received badge  Supporter (source)
2015-07-03 00:20:25 -0600 commented answer How to fix resized image in MFC?

@pklab, no, if WindowWidth(1rc.Width()1) is 13, then pad=13%4=1. rc.right-=1 so that rc.Width()=12. Finally the mat resized to rc.Width()=mat.cols=12 is OK!(Since I'd - the pad, but u + padding.)

4 is OK, that's if [some width] =4n, pad=[some width]%4=0. So that [some width]-=0 is OK.

2015-07-03 00:05:33 -0600 received badge  Scholar (source)
2015-06-29 05:50:33 -0600 commented answer How to fix resized image in MFC?

I'd do control the client rectangle with if(int pad=%rc.Width()%4) rc.right-=pad; within WM_SIZE, It's OK now. Thank you very much!!

2015-06-26 05:59:47 -0600 asked a question How to fix resized image in MFC?

Hi, it was ok when run following code to paint Mat on Device Contro/DC/CDC:

Visual Studio 2010, MFC, OpenCV 247

image description

void CMainDlg::OnPaint()
{
    CRect rc; GetClientRect(&rc);
    CClientDC dc(this);

    Mat mat; mat=imread("aaa.bmp");
    int x=mat.cols;
    int y=mat.rows;

    // Create BitmapInfo
    BITMAPINFO bmi;
    BITMAPINFOHEADER* pheader= &bmi.bmiHeader;
    pheader->biSize         = sizeof( BITMAPINFOHEADER );
    pheader->biPlanes       = 1;
    pheader->biCompression   = BI_RGB;
    pheader->biXPelsPerMeter = 100;
    pheader->biYPelsPerMeter = 100;
    pheader->biClrUsed      = 0;
    pheader->biClrImportant  = 0;
    pheader->biWidth    = x;
    pheader->biHeight   = -y;
    pheader->biBitCount = 24;
    bmi.bmiHeader.biSizeImage = 0;

    // Stretch Image
    StretchDIBits( dc.GetSafeHdc()
                ,0,0,rc.Width(), rc.Height()
                ,0,0,x,y,
                mat.data,&bmi,DIB_RGB_COLORS,SRCCOPY);

    // Compare
    imshow("CV imshow()",mat);
}

in a MFC dialog(CDialogEx), but when I resize the mat like this

void CMainDlg::OnPaint()
{
    CRect rc; GetClientRect(&rc);
    CClientDC dc(this);

    Mat mat; mat=imread("aaa.bmp");
    resize(mat,mat,cv::Size(rc.Width(),rc.Height()));
    int x=mat.cols;
    int y=mat.rows;
    // ...some code...
}

the image got in shift!? why??

Resoult:

image description

There's same case in:

  1. Move mat to global area.

  2. paint in other function(out of OnPaint())