也就是说,
我建立了一个基于dialog的工程,
我想打开图像,
然后在这个dialog里显示,
然后可以进行图像放大,缩小,平移等操作,我拖一个picture control,
但是好象不行啊……哪位知道该怎么做啊?要是哪位给一个示例代码就更好了[email protected]

解决方案 »

  1.   

    要显示的话,直接在下拉菜单里选择,在这个之前要把属性设置成bitmap(资源的属性对话框里)
    要改变大小等就要coding
      

  2.   

    CxImage Sample
    http://www.codeproject.com/listctrl/ThumbsViewer.asp使用的是CxImage库对多种图像进行显示,可以参考这个例子的显示缩略图的那部分代码!
      

  3.   

    如果只是BMP图片参考下面的代码:
    void CCreateRandomBMPDlg::OnBtnTest()
    {
    // TODO: Add your control notification handler code here
    HBITMAP hBmp; CFileDialog dlg(TRUE, "bmp", NULL, 0, "位图文件 (*.bmp)|*.bmp||", this); if (dlg.DoModal() != IDOK)
    {
    return;
    } hBmp = (HBITMAP) LoadImage(NULL, dlg.GetPathName(), IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hBmp == NULL)
    {
    return;
    } BITMAP bm;
    PBITMAPINFO bmpInf; if (GetObject(hBmp, sizeof(bm), &bm) == 0)
    return ; int nPaletteSize = 0; if (bm.bmBitsPixel < 16)
    nPaletteSize = (int) pow(2, bm.bmBitsPixel); bmpInf = (PBITMAPINFO) LocalAlloc(LPTR,
    sizeof(BITMAPINFOHEADER) +
    sizeof(RGBQUAD) * nPaletteSize); //-----------------------------------------------
    bmpInf->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpInf->bmiHeader.biWidth = bm.bmWidth;
    bmpInf->bmiHeader.biHeight = bm.bmHeight;
    bmpInf->bmiHeader.biPlanes = bm.bmPlanes;
    bmpInf->bmiHeader.biBitCount = bm.bmBitsPixel;
    bmpInf->bmiHeader.biCompression = BI_RGB;
    bmpInf->bmiHeader.biSizeImage = (bm.bmWidth + 7) /
    8 * bm.bmHeight * bm.bmBitsPixel;
    bmpInf->bmiHeader.biXPelsPerMeter = 0;
    bmpInf->bmiHeader.biYPelsPerMeter = 0;
    bmpInf->bmiHeader.biClrUsed = 0;
    bmpInf->bmiHeader.biClrImportant = 0;
    //----------------------------------------------- HDC hDC = ::GetWindowDC(NULL);
    if (!::GetDIBits(hDC, hBmp, 0, (WORD) bm.bmHeight, NULL, bmpInf,
    DIB_RGB_COLORS))
    {
    LocalFree(bmpInf);
    ::ReleaseDC(NULL, hDC);
    return ;
    } void* buf = (void*) new char[bmpInf->bmiHeader.biSizeImage];
    if (buf == NULL)
    {
    ::ReleaseDC(NULL, hDC);
    LocalFree(bmpInf);
    return ;
    } if (!::GetDIBits(hDC, hBmp, 0, (UINT) bm.bmHeight, buf, bmpInf,
    DIB_RGB_COLORS))
    {
    ::ReleaseDC(NULL, hDC);
    delete[]buf;
    LocalFree(bmpInf);
    return ;
    } ::ReleaseDC(NULL, hDC); CString sMsg;
    sMsg.Format("BitsPixel:%d,width:%d,height:%d", bm.bmBitsPixel, bm.bmWidth,
    bm.bmHeight); AfxMessageBox(sMsg); CClientDC dc(this); if (bm.bmBitsPixel == 8)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth;
    while (nWidth % 4 != 0)
    {
    //Bmp每行数据都是4个字节的整数倍。
    nWidth++;
    } for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    RGBQUAD rgbQ;
    rgbQ = bmpInf->bmiColors[pData[i * nWidth + j]];
    dc.SetPixel(j, bm.bmHeight - i,
    RGB(rgbQ.rgbRed, rgbQ.rgbGreen, rgbQ.rgbBlue));
    }
    }
    }
    else if (bm.bmBitsPixel == 16)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*2;
    while (nWidth % 4 != 0)
    {
    nWidth++;
    } BYTE red, green, blue; for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    blue = pData[i * nWidth + j * 2] & 0x1F;
    green = pData[i * nWidth + j * 2] >> 5;
    green |= (pData[i * nWidth + j * 2 + 1] & 0x03) << 3;
    red = (pData[i * nWidth + j * 2 + 1] >> 2) & 0x1F; WORD wRed = red*8;
    WORD wBlue = blue*8;
    WORD wGreen = green*8; red = min(255, wRed);
    blue = min(255, wBlue);
    green = min(255, wGreen); dc.SetPixel(j, bm.bmHeight - i, RGB(red, green, blue));
    }
    }
    }
    else if (bm.bmBitsPixel == 24)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*3;
    while (nWidth % 4 != 0)
    {
    nWidth++;
    } for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    dc.SetPixel(j, bm.bmHeight -
    i,
    RGB(pData[i * nWidth + j * 3 + 2],
    pData[i * nWidth + j * 3 + 1],
    pData[i * nWidth + j * 3]));
    }
    }
    }
    else if (bm.bmBitsPixel == 32)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*4; for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    dc.SetPixel(j, bm.bmHeight -
    i,
    RGB(pData[i * nWidth + j * 4 + 2],
    pData[i * nWidth + j * 4 + 1],
    pData[i * nWidth + j * 4]));
    }
    }
    } delete[]buf; DeleteObject(hBmp);
    LocalFree(bmpInf);
    }
    这是将你选择的图片显示到屏幕的,你可以将HDC hDC = ::GetWindowDC(NULL);改为获得你的Picture控件的DC即可显示到控件中了!
      

  4.   

    gamezealot(≯未成年+迷失本性=良牙≮) :
    “直接在下拉菜单里选择”?怎么选择?
      

  5.   

    vcleaner(我没做大哥已经很久了.......) :
    那个地方的代码下载不了啊
    我找了半天也没找到在哪里可以注册啊
      

  6.   

    vcleaner(我没做大哥已经很久了.......) :
    你的代码里是把bmp里的数据读出来然后再SetPixel,
    那我如果打开的图像是jpg或tif其他格式的图像呢?
      

  7.   

    “新的类库 CxImage”?
    这个在哪里可以下载到
      

  8.   

    to vcleaner(我没做大哥已经很久了.......) :
    注册了半天,总算是下载下来了:)cximagecrt.dll这个动态库有源码没有哇?
      

  9.   

    vcleaner
    =====================================================
    他一个人都说完裘了,没裘的说的了