怎样把一个RGB24的位图保存到像素点数组中,急等...

解决方案 »

  1.   

    如果是位图文件
    则根据位图文件结构读取BITMAPFILEHEADER、BITMAPINFOHEADER、RGBQUAD、DATA ARRAY(后者即是你要的像素点数组)如果是位图object
    则使用GetDIBits获得DATA ARRAYsetpixel你可以对Bitmap对象或者在dc中操作
      

  2.   

    我是用loadbitmap直接加载一张位图
      

  3.   

    pData   =   new   UINT[cxSource  *  cySource]; 
                    BITMAPINFO   bmpInfo; 
                    bmpInfo.bmiHeader.biSize   =   sizeof(BITMAPINFOHEADER); 
                    bmpInfo.bmiHeader.biWidth   =   cxSource; 
                    bmpInfo.bmiHeader.biHeight  =   -cySource; 
                    bmpInfo.bmiHeader.biPlanes   =   1; 
                    bmpInfo.bmiHeader.biCompression   =   BI_RGB; 
                    bmpInfo.bmiHeader.biBitCount   =   24;                 GetDIBits(hdc, hTree, 0, cySource, pData, &bmpInfo, DIB_RGB_COLORS); 
    pData保存像素点数组,怎么取像素点的RGB值
      

  4.   

    loadbitmap后选入内存dc,然后用getPixel应该就能获得相应位置的RGB值
      

  5.   

    loadbitmap直接加载一张位图
    GetPixel得到像素值
      

  6.   

    pData   =   new   UINT[cxSource  *  cySource];
    大小错了,每行要四字节对齐应该是
    pData   =   new   UINT[((cxSource*3+3)/4*4)  *  cySource];取像素值
    1。 GetPixel
    2。 数组中(注意每行数据以4字节补齐,以及位图数据的存储方向,一般从下至上)
      

  7.   

    GetPixel可行但太慢。现在用4个像素点来表示一个像素点,应该怎没做?
      

  8.   


    hdc = BeginPaint (hwnd, &ps) ;
    hdcMem = CreateCompatibleDC (hdc) ;
                    SelectObject (hdcMem, hbmp) ;
    StretchBlt (hdc, 0, 0, 256, 256, hdcMem, 0, 0, cxSource, cySource, MERGECOPY) ;                bh.bmiHeader.biSize   =   sizeof(bh.bmiHeader); 
                    GetDIBits(hdc, hbmp, 0, 0, NULL, &bh, DIB_RGB_COLORS);   //   查询BITMAPINFO   
    if (bh.bmiHeader.biBitCount   ==   24) 
                    nBitClrUsed   =   3;     //   每个像素占用的字节数
                    bits  = new   BYTE[bh.bmiHeader.biWidth   *   bh.bmiHeader.biHeight   *   nBitClrUsed]; 
                    GetDIBits(hdc,   hbmp,   0,   bh.bmiHeader.biHeight,   bits,   &bh,   DIB_RGB_COLORS); 
                    //   获得整张位图的数据,保存到bits指向的空间
                    COLORREF PixelArray[1000][1000];
                    for(y=0;y<bh.bmiHeader.biHeight;y++)
                   {
                         for(x=0;x<bh.bmiHeader.biWidth;x++)
                         {
                               BYTE bBlue = bits[bh.bmiHeader.biWidth*y*3+3*x+0];   
                               BYTE bGreen = bits[bh.bmiHeader.biWidth*y*3+3*x+1];   
                               BYTE bRed = bits[bh.bmiHeader.biWidth*y*3+3*x+2];   
                               PixelArray[bh.bmiHeader.biHeight-y][x]=RGB(bBlue, bGreen, bRed); 
       SetPixel(hdc, x+256, y, PixelArray[bh.bmiHeader.biHeight-y][x]);
     }
    }

    DeleteDC (hdcMem) ;
    EndPaint (hwnd, &ps) ;那位大哥帮忙修改一下