GetBItmapBits()
-
Hi, I am loading a bmp file through LoadImage() and accessing the image data through GetBitmapBits(). Now i am saving the data as follows: BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; CFile file; if( !file.Open( the_filename, CFile::modeWrite|CFile::modeCreate) ) return FALSE; lpbi = (LPBITMAPINFOHEADER)m_pFirstBuffer ; lpbi->biBitCount=24; int nColors = 1 << 24; if(nColors> 256) nColors=0; lpbi->biClrUsed=0; lpbi->biSize=40; lpbi->biHeight =(DWORD)bmp.bmHeight; lpbi->biWidth=(DWORD)bmp.bmWidth ; lpbi->biXPelsPerMeter =lpbi->biYPelsPerMeter =0; lpbi->biClrImportant =0; lpbi->biPlanes =1; lpbi->biCompression =0; lpbi->biSizeImage = bmp.bmHeight *bmp.bmWidthBytes ; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + lpbi->biSize + lpbi->biClrUsed* sizeof(RGBQUAD) + lpbi->biSizeImage); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; if (lpbi->biBitCount > 0 && lpbi->biBitCount <= 8) { hdr.bfOffBits = (DWORD)(sizeof(hdr) + lpbi->biSize +nColors * sizeof(RGBQUAD)); } else { unsigned long cmapsize = 0; switch (lpbi->biBitCount) { case 16: case 32: if (lpbi->biCompression == BI_BITFIELDS) { cmapsize = 3*sizeof(DWORD); } break; case 24: cmapsize = lpbi->biClrUsed*sizeof(RGBQUAD); break; default: // no colormap break; } hdr.bfOffBits = (DWORD)(sizeof(hdr) + lpbi->biSize + cmapsize); } // Write the file header file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits file.Write( lpbi, lpbi->biSize ); file.Write( m_pFirstBuffer, bmp.bmHeight *bmp.bmWidthBytes ); file.Close (); Now i could open the saved file in Windows Paint application but if i call LoadImage() with that file name as parameter it returns NULL. GetLastError() is zero. Could anyone tell me where i am wrong? Regards Neha
-
Hi, I am loading a bmp file through LoadImage() and accessing the image data through GetBitmapBits(). Now i am saving the data as follows: BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; CFile file; if( !file.Open( the_filename, CFile::modeWrite|CFile::modeCreate) ) return FALSE; lpbi = (LPBITMAPINFOHEADER)m_pFirstBuffer ; lpbi->biBitCount=24; int nColors = 1 << 24; if(nColors> 256) nColors=0; lpbi->biClrUsed=0; lpbi->biSize=40; lpbi->biHeight =(DWORD)bmp.bmHeight; lpbi->biWidth=(DWORD)bmp.bmWidth ; lpbi->biXPelsPerMeter =lpbi->biYPelsPerMeter =0; lpbi->biClrImportant =0; lpbi->biPlanes =1; lpbi->biCompression =0; lpbi->biSizeImage = bmp.bmHeight *bmp.bmWidthBytes ; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + lpbi->biSize + lpbi->biClrUsed* sizeof(RGBQUAD) + lpbi->biSizeImage); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; if (lpbi->biBitCount > 0 && lpbi->biBitCount <= 8) { hdr.bfOffBits = (DWORD)(sizeof(hdr) + lpbi->biSize +nColors * sizeof(RGBQUAD)); } else { unsigned long cmapsize = 0; switch (lpbi->biBitCount) { case 16: case 32: if (lpbi->biCompression == BI_BITFIELDS) { cmapsize = 3*sizeof(DWORD); } break; case 24: cmapsize = lpbi->biClrUsed*sizeof(RGBQUAD); break; default: // no colormap break; } hdr.bfOffBits = (DWORD)(sizeof(hdr) + lpbi->biSize + cmapsize); } // Write the file header file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits file.Write( lpbi, lpbi->biSize ); file.Write( m_pFirstBuffer, bmp.bmHeight *bmp.bmWidthBytes ); file.Close (); Now i could open the saved file in Windows Paint application but if i call LoadImage() with that file name as parameter it returns NULL. GetLastError() is zero. Could anyone tell me where i am wrong? Regards Neha
Hi Neha, Actually , While saving the BITMAP u converted it into Device independent Bitmap.and LoadImage API cannot load DIB's , it can load only icon, cursor, animated cursor, or bitmap or OEM Bitmaps. If u want to display this Bitmap, then u have to read the file by your own code ,get the BMP data in a buffer prepare headers, and u can use APIs like DrawDibDraw to draw ur image :) Regards Abhishek Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
Hi Neha, Actually , While saving the BITMAP u converted it into Device independent Bitmap.and LoadImage API cannot load DIB's , it can load only icon, cursor, animated cursor, or bitmap or OEM Bitmaps. If u want to display this Bitmap, then u have to read the file by your own code ,get the BMP data in a buffer prepare headers, and u can use APIs like DrawDibDraw to draw ur image :) Regards Abhishek Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
I think you got confussed. I am using GetBitmapBits() it returns device dependent bitmap. In LoadImage() i am setting LOADFROMFILE. this will returns us the HBITMAP.I mean to say the value returned from LoadImage() ie HBITMAP is NULL.
// Write the DIB header and the bits file.Write( lpbi, lpbi->biSize ); check these above line of ur code In ur Submitted code , u have created this DIB header, Which states that the BMP u created is DIB,and let me know if u the file extension is .bmp then that means u have created an DIB image , thats why LoadImage fails. Check few artilces for .bmp files , u can see these Windows supported Picture files are Device independent. Even if u used the GetBitmapBits , but while saving u converted it into DIB Regards Abhishek :) http://www.prepressure.com/formats/bmp/fileformat.htm Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
// Write the DIB header and the bits file.Write( lpbi, lpbi->biSize ); check these above line of ur code In ur Submitted code , u have created this DIB header, Which states that the BMP u created is DIB,and let me know if u the file extension is .bmp then that means u have created an DIB image , thats why LoadImage fails. Check few artilces for .bmp files , u can see these Windows supported Picture files are Device independent. Even if u used the GetBitmapBits , but while saving u converted it into DIB Regards Abhishek :) http://www.prepressure.com/formats/bmp/fileformat.htm Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
Well the extension doe'snt matter, what i think is that u r saving it as DIB :) and even ur extension says it is a DIB :-D.... try to read it as a DIB image may be it will solve ur issue!! Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
Well the extension doe'snt matter, what i think is that u r saving it as DIB :) and even ur extension says it is a DIB :-D.... try to read it as a DIB image may be it will solve ur issue!! Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)