Winapi wczytanie kolorow bitmapy do macierzy -error


(Ganda666) #1

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


(Ryan) #2

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


(Ganda666) #3
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.