在MFC对话框上绘制图像像素阵列

时间:2015-03-06 00:59:23

标签: c++ image mfc dialog gdi+

我有一个'pbm'图像,其内容被加载到IMAGE对象中,该对象定义如下。

我当前的问题是如何在MFC对话框上绘制这张图片(我当前想在MFC对话框上绘制它)。我下面的代码不会产生任何结果。

struct header {
    int nr, nc;             /* Rows and columns in the image */
    int oi, oj;             /* Origin */
};

/*      The IMAGE data structure        */
struct image {
        struct header *info;            /* Pointer to header */
        unsigned char **data;           /* Pixel values */
};

void CSampleDlg::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    char* lpszPathName = "TESTPAGE.PBM";
    IMAGE image = Input_PBM(lpszPathName);
    for(int i=0; i< image->info->nc; i++){
        for(int j=0; j< image->info->nr; j++){
            unsigned char pixel = image->data[j][i];
           //pixel value is either 0  or 1..
            dc.SetPixel(i,j,pixel);   //PLOT The whole image....
        }   
    }

    Invalidate(0);
}

HRESULT CSampleDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
    OnPaint();
    return S_OK;
}

OnPaint()中,我调用dc-&gt; setPixel(..)通过绘制每个像素来重绘整个图像。但对话框没有改变......

0 个答案:

没有答案