小弟现在已经对一副648*488的BMP格式的图片进行了分析其中分别得到了R。G。B的值分别用三个两维数组存放,现在我想对每一个数组进行读取当我点击一个button时候 就能将其在一个新的窗口中显示出来。我用的SDK编程,利用这个SetDIBitsToDevice函数我不知道怎么来实现!请高手指点指点!!

解决方案 »

  1.   

    int iWidth, iHeight, iBytesWidth;
    iWidth = 500;
    iHeight = 500;
    float dTemp = 960;
    iBytesWidth = (iWidth % 4) ? (iWidth / 4 + 1) * 4 : iWidth;
    HANDLE hMem = GlobalAlloc(GMEM_MOVEABLE, iBytesWidth * iHeight * 3);
            BYTE *Image = (BYTE*)GlobalLock(hMem);//new BYTE[iBytesWidth * iHeight * 3];
    //memset(Image, 100, iBytesWidth * iHeight * 3);
    BITMAPINFO bmi;
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = iWidth;
    bmi.bmiHeader.biHeight = iHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 24;
    bmi.bmiHeader.biCompression = BI_RGB;
    ::SetDIBitsToDevice(pDC->GetSafeHdc(), 0, 0, iWidth, iHeight, 0, 0, 0, iHeight, Image, &bmi, DIB_RGB_COLORS);
    GlobalUnlock(hMem);
    GlobalFree(hMem);
    delete []Image;
      

  2.   

    谢谢~~~
    extern void R_Show(HWND hwnd)
    {
        static BITMAPINFO *pbmi;
        static BYTE *pBits;

    HDC hdc = GetDC(hwnd);
    pBits = *pRArray;(pRArray存放R值的一个二维数组)
      
    pbmi->bmiHeader.biSize              = sizeof(BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth             = IMAGEWIDTH/2;
    pbmi->bmiHeader.biHeight            = IMAGEHEIGHT/2;
    pbmi->bmiHeader.biPlanes            = 1;
    pbmi->bmiHeader.biBitCount          = 1;
    pbmi->bmiHeader.biCompression       = BI_RGB;
    pbmi->bmiHeader.biSizeImage         = 0;
    pbmi->bmiHeader.biXPelsPerMeter     = 0;
    pbmi->bmiHeader.biYPelsPerMeter     = 0;
    pbmi->bmiHeader.biClrUsed           = 0;
    pbmi->bmiHeader.biClrImportant      = 0; SetDIBitsToDevice (hdc,0,0,IMAGEWIDTH/2,IMAGEHEIGHT/2,0,0,0,IMAGEHEIGHT/2,
                   pBits,pbmi,DIB_RGB_COLORS) ;}为什么我这么写怎么就报错啊?说什么内存不能写?
    请指点一下
      

  3.   

    pBits = *pRArray;
    static BYTE *pBits;
    pBits好像是指针吧。