//省略很多的关于显示的代码
CBitmap bitmap;
BITMAP bm;
//.....//
bitmap->GetBitmap(&bm);
int bitmapsize=bm.bmHeight*bm.bmwidthBytes;
BYTE* px=(BYTE*)GlobalAlloc(GPTR,bitmapsize);//声明px数组,可惜是一维的
DWORD dwvalue;
dwvalue=bitmap->GetBitmapBus(bitmapsize,px);int rgb,x,y;
int PixelBytes=bm.bmBitsPixel/8;
for(y=0;y<bm.bmHeight;y++)
for(x=0;x<bm.bmwidth;x++)
{
rgb=y*bm.bmwidthBytes+x*pixelBytes;
px[rgb+0]...//读取R
px[rgb+1]...//读取G
px[rgb+2]...//读取B
}                                //bmp图象
我的问题是怎样声明一个数组来存放32bit图象的灰度?
我知道RGB与GRAY之间的关系

解决方案 »

  1.   

    想得到一个整形的数组。GlobalAlloc怎么用,讲解一下
      

  2.   

    GlobalAlloc就可以嘛
    只是用过别忘了GlobalFree就行了
      

  3.   

    GlobalLock
    GlobalAlloc
    The GlobalAlloc function allocates the specified number of bytes from the heap. HGLOBAL GlobalAlloc(
      UINT uFlags,    // allocation attributes
      DWORD dwBytes   // number of bytes to allocate
    );
     LPVOID GlobalLock(
      HGLOBAL hMem   // handle to the global memory object
    );
     
    Parameters
    hMem 
    Handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function. 
    Return Values
    If the function succeeds, the return value is a pointer to the first byte of the memory block.
      

  4.   

    HGLOBAL hHnd = GlobalAlloc(GMEM_FIXED,sizeof(int)*Num);
    int * lpBits = GlobalLock(hHnd);
    GlobalFree(hHnd );
      

  5.   

    对了,还得这个一下
    BOOL GlobalUnlock(
      HGLOBAL hMem   // handle to the global memory object
    );