Unable to Save window image to BMP file on disk 
Author Message
 Unable to Save window image to BMP file on disk
Hi

Can Anybody help me out in saving my window image in bmp format on disk.

Actually I capturing the images and those images I had to save in the bmp
format.

My code is like this and what actually I write to make u understand my
problem.
I am getting the dimensions of the image proper but palettesize might be
giving problem.

****************************************************************************
*****************

DWORD CDib::Save(CFile& file,HDIB hDib)
{

 BITMAPFILEHEADER hdr;
 DWORD dwDIBSize;

 DIBSECTION ds;
  VERIFY(GetObject(sizeof(ds), &ds)==sizeof(ds));
 char buf[sizeof(BITMAPINFOHEADER) + MAXPALCOLORS*sizeof(RGBQUAD)];
 BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER*)buf;
 RGBQUAD* colors = (RGBQUAD*)(&bmih+1);

 memcpy(&bmih, &ds.dsBmih, sizeof(bmih));

 if(hDib == NULL)
  return 0;

 if (&bmih == NULL)
  return 0;

 //fill the fields of file header
 // fill the file type( first two will be "BM")

 hdr.bfType = DIB_HEADER_MARKER;

 //Calculating the size of DIB

 // First find the size of header plus size of color table.
 //the first DWORD in BITMAPINFOHEADER and BITMAPCOREHEADER contains
 //the size of the structure

 //Now Calculate the size of the Palette

 if((bmih.biCompression = BI_RLE8) || (bmih.biCompression  == BI_RLE4))
 {

  dwDIBSize +=bmih.biSizeImage;

 }
 else
 {
  DWORD dwBmBitsSize;   //Size of the Bitmap Bits only

  //It's not RLE,so size is width (DWORD aligned) * Height

  dwBmBitsSize = WIDTHBYTES((bmih.biWidth ) * ((DWORD)bmih.biBitCount)) *
bmih.biHeight;
  dwDIBSize +=dwBmBitsSize;

  bmih.biSizeImage = dwBmBitsSize;

 }

 //Calculating the file size by adding the DIB size to
sizeof(BITMAPFILEHEADER)
 hdr.bfSize = dwDIBSize + sizeof(BITMAPFILEHEADER);
 hdr.bfReserved1 = 0;
 hdr.bfReserved2 = 0;

 //now calculate the offset

 hdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + bmih.biSize +
PaletteSize();

 //Write the file header

 file.Write ((LPSTR)&hdr,sizeof(BITMAPFILEHEADER));
 DWORD dwBytesSaved = sizeof(BITMAPFILEHEADER);

 // Write the DIB header

 UINT nCount = sizeof(BITMAPINFO) +
(GetColorTable(colors,MAXPALCOLORS)*sizeof(RGBQUAD));

 nCount = sizeof(BITMAPINFO) +(NumColors()-1)*sizeof(RGBQUAD);
 dwBytesSaved += nCount;

 file.Write (&bmih,nCount);

 // Write the DIB bits

 DWORD dwBytes = bmih.biBitCount * bmih.biWidth; //Width();
 // Calculate the number of bytes per line
 if (dwBytes%32 == 0)
  dwBytes /= 8;
 else
  dwBytes = dwBytes/8 + (32-dwBytes%32)/8 + (((32-dwBytes%32)%8 > 0) ? 1 :
0);
 nCount = dwBytes * bmih.biHeight; //Height();
 dwBytesSaved += nCount;

 //file.WriteHuge (m_bm.bmBits ,nCount);

 /*
 if (pOldPal)
  memdc.SelectPalette(pOldPal, TRUE);
 */
 return dwBytesSaved;

Quote:
}




Tue, 29 Jan 2002 03:00:00 GMT  
 Unable to Save window image to BMP file on disk

Quote:

>Hi

>Can Anybody help me out in saving my window image in bmp format on disk.

>Actually I capturing the images and those images I had to save in the bmp
>format.

>My code is like this and what actually I write to make u understand my
>problem.
>I am getting the dimensions of the image proper but palettesize might be
>giving problem.

>***************************************************************************
*
>*****************

>DWORD CDib::Save(CFile& file,HDIB hDib)
>{

> BITMAPFILEHEADER hdr;
> DWORD dwDIBSize;

> DIBSECTION ds;
>  VERIFY(GetObject(sizeof(ds), &ds)==sizeof(ds));
> char buf[sizeof(BITMAPINFOHEADER) + MAXPALCOLORS*sizeof(RGBQUAD)];
> BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER*)buf;
> RGBQUAD* colors = (RGBQUAD*)(&bmih+1);

> memcpy(&bmih, &ds.dsBmih, sizeof(bmih));

> if(hDib == NULL)
>  return 0;

> if (&bmih == NULL)
>  return 0;

> //fill the fields of file header
> // fill the file type( first two will be "BM")

> hdr.bfType = DIB_HEADER_MARKER;

> //Calculating the size of DIB

> // First find the size of header plus size of color table.
> //the first DWORD in BITMAPINFOHEADER and BITMAPCOREHEADER contains
> //the size of the structure

> //Now Calculate the size of the Palette

> if((bmih.biCompression = BI_RLE8) || (bmih.biCompression  == BI_RLE4))
> {

>  dwDIBSize +=bmih.biSizeImage;

> }
> else
> {
>  DWORD dwBmBitsSize;   //Size of the Bitmap Bits only

>  //It's not RLE,so size is width (DWORD aligned) * Height

>  dwBmBitsSize = WIDTHBYTES((bmih.biWidth ) * ((DWORD)bmih.biBitCount)) *
>bmih.biHeight;
>  dwDIBSize +=dwBmBitsSize;

>  bmih.biSizeImage = dwBmBitsSize;

> }

> //Calculating the file size by adding the DIB size to
>sizeof(BITMAPFILEHEADER)
> hdr.bfSize = dwDIBSize + sizeof(BITMAPFILEHEADER);
> hdr.bfReserved1 = 0;
> hdr.bfReserved2 = 0;

> //now calculate the offset

> hdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + bmih.biSize +
>PaletteSize();

> //Write the file header

> file.Write ((LPSTR)&hdr,sizeof(BITMAPFILEHEADER));
> DWORD dwBytesSaved = sizeof(BITMAPFILEHEADER);

> // Write the DIB header

> UINT nCount = sizeof(BITMAPINFO) +
>(GetColorTable(colors,MAXPALCOLORS)*sizeof(RGBQUAD));

> nCount = sizeof(BITMAPINFO) +(NumColors()-1)*sizeof(RGBQUAD);
> dwBytesSaved += nCount;

> file.Write (&bmih,nCount);

> // Write the DIB bits

> DWORD dwBytes = bmih.biBitCount * bmih.biWidth; //Width();
> // Calculate the number of bytes per line
> if (dwBytes%32 == 0)
>  dwBytes /= 8;
> else
>  dwBytes = dwBytes/8 + (32-dwBytes%32)/8 + (((32-dwBytes%32)%8 > 0) ? 1 :
>0);
> nCount = dwBytes * bmih.biHeight; //Height();
> dwBytesSaved += nCount;

> //file.WriteHuge (m_bm.bmBits ,nCount);

> /*
> if (pOldPal)
>  memdc.SelectPalette(pOldPal, TRUE);
> */
> return dwBytesSaved;

>}



Sat, 02 Feb 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: save picture from window to disk (as bmp)

2. Saving BMP Files to Disk

3. Saving a whole covered window to BMP file

4. writing a window image to a bmp file?

5. Code query - Unable to save images???

6. saving images to disk

7. Capturing part of a window and saving as a BMP

8. Saving contents of window to .bmp or .gif

9. Save window in BMP,DIB etc

10. Windows .BMP Images

11. URGENT : How to save bitmaps into bmp files.

12. Saving CBitmap to a bmp file

 

 
Powered by phpBB® Forum Software