Winapi wczytanie kolorow bitmapy do macierzy -error

Witam,

napisalem funkcje w winapi, ktora wczytuje bity z bitmapy (24 bit) do macierzy. Kompiluje sie, ale niestety dziala niepoprawnie-zwraca zle wartosci. Nie moge znalezc bledu. Oto kod:

int*** LoadBMPfromClipboard(HBITMAP hBMP,HDC hDC)

{

HANDLE hf; // file handle

BITMAPFILEHEADER hdr; // bitmap file-header

PBITMAPINFOHEADER pbih; // bitmap info-header

LPBYTE lpBits; // memory pointer

DWORD dwTotal; // total count of bytes

DWORD cb; // incremental count of bytes

BYTE *hp; // byte pointer

DWORD dwTmp;

PBITMAPINFO pbi;

pbi=CreateBitmapInfoStruct(hBMP);

int height,width,depth;

pbih = (PBITMAPINFOHEADER) pbi;

lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

//! !!

// errhandler(“GlobalAlloc”, hwnd);

// Retrieve the color table (RGBQUAD array) and the bits

// (array of palette indices) from the DIB.

GetDIBits(hDC, hBMP, 0, (WORD) pbih-biHeight, lpBits, pbi,

DIB_RGB_COLORS);

/* !!

DIB_RGB_COLORS))

{

errhandler(“GetDIBits”, hwnd);

}

*/

width = pbi-bmiHeader.biWidth;

height = pbi-bmiHeader.biHeight;

depth = 24;

//////make an array

int ***array;

array = new int **[height];

for(int i=0;i

array = new int*[width];

for(int i=0;i

for(int j=0;j

{

// if( depth == 1)

// array_[j]= new float[1];_

// else if(depth == 32)

// array_[j]= new float[4];_

// else if(depth == 24)

array_[j]= new int[3];_

}

//////put JPEG to array

hp = lpBits;

for(int i=0;i

for(int j=0;j

{

/* if( depth == 1)

{

}

else if(depth == 32)

{

} */

//else if(depth == 24)

//{

array_[j][0]= *hp++;_

array_[j][1]= *hp++;_

array_[j][2]= *hp++;_

//}

}

return array;

}

Z gory dziekuje za pomoc.

Pozdrawiam

Użyj znacznika [code] - to co wkleiłeś jest zupełnie nieczytelne.

int*** LoadBMPfromClipboard(HBITMAP hBMP,HDC hDC)

{

        HANDLE hf; // file handle 

    BITMAPFILEHEADER hdr; // bitmap file-header 

    PBITMAPINFOHEADER pbih; // bitmap info-header 

    LPBYTE lpBits; // memory pointer 

    DWORD dwTotal; // total count of bytes 

    DWORD cb; // incremental count of bytes 

    BYTE *hp; // byte pointer 

    DWORD dwTmp; 


   PBITMAPINFO pbi; 

   pbi=CreateBitmapInfoStruct(hBMP);

   int height,width,depth;


       pbih = (PBITMAPINFOHEADER) pbi; 

    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

//!! if (!lpBits) 

      // errhandler("GlobalAlloc", hwnd); 

    // Retrieve the color table (RGBQUAD array) and the bits 

    // (array of palette indices) from the DIB. 

GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, 

        DIB_RGB_COLORS);

/*!! if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, 

        DIB_RGB_COLORS)) 

    {

        errhandler("GetDIBits", hwnd); 

    }

*/

width = pbi->bmiHeader.biWidth;

height = pbi->bmiHeader.biHeight;

depth = 24;

  //////make an array 

  int ***array;

     array = new int **[height];

      for(int i=0;i
      array[i] = new int*[width];

      for(int i=0;i
              for(int j=0;j
              {

                     // if( depth == 1)

                     // array[i][j]= new float[1];

                     // else if(depth == 32)

                     // array[i][j]= new float[4];

                     // else if(depth == 24)                    

                      array[i][j]= new int[3];

              }

  //////put JPEG to array

    dwTotal = cb = pbih->biSizeImage; 

    hp = lpBits; 


    // tylko dla RGB 24bit

int skip_alignment=4-((width*3)%4);


for(int i=0;i
{

   for(int j=0;j
   {

       array[i][j][0]= hp[0];

       array[i][j][1]= hp[1];

       array[i][j][2]= hp[2];

       hp+=3;

    }


    hp+=skip_alignment;

}


 /*   


        for(int i=0;i
              for(int j=0;j
              {

                if( depth == 1)  

                {



                }    

                else if(depth == 32)  

                {


                }         

                else if(depth == 24)    

                { 

                     array[i][j][0]= *hp++;

                     array[i][j][1]= *hp++;

                     array[i][j][2]= *hp++;

                }           

              } */


  return array;    

}  

[/code]

Mam nadzieje, ze teraz jest ok.