Create a CBitmap object, draw in it, save in (.bmp file)
-
in my Document class the function serialize... I wan,t to save my data as a monochrome bitmap so I do
void CWoopDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
//I need a bitmap object
CBitmap BitMapTemp;
//a device context to draw on it
CDC CBitmapDC;
CBitmap* OldBitMap;//initialisation of the dc CBitmapDC.CreateCompatibleDC(NULL);
//here I'm not sure of that... I guess
//I create an array of bytes for the bitmap void \* bitmapbitstemp = malloc( Size\_X\*Size\_Y / sizeof(BYTE)); //here I create the bitmap BitMapTemp.CreateBitmap(Size\_X,Size\_Y,1,1,bitmapbitstemp); //I send my bitmap to the DC and save the old one OldBitMap = CBitmapDC.SelectObject(&BitMapTemp); //(... I draw in it) //now I wan't to save it //I need a bitmapInfoHeader and A bitMap File Header BITMAPFILEHEADER BmpFileH; BITMAPINFOHEADER bmpInfoH; BITMAP bm; BitMapTemp.GetBitmap(&bm); //<--here I'm unable the get the bitmap bits, but the creation return true!!! BmpFileH.biBitCount = bm.bmBitsPixel; BmpFileH.biCompression = BI\_RGB; BmpFileH.biHeight = bm.bmHeight; BmpFileH.biPlanes = bm.bmPlanes; BmpFileH.biWidth = bm.bmWidth; BmpFileH.biSizeImage = BI\_RGB; BmpFileH.biClrUsed = 0; BmpFileH.biClrImportant = 2; BmpFileH.biXPelsPerMeter = 0; BmpFileH.biYPelsPerMeter = 0; BmpFileH.biSize = sizeof(BmpFileH); bmpInfoH.bfOffBits = sizeof(bmpInfoH)+sizeof(BmpFileH); bmpInfoH.bfSize = bm.bmWidthBytes; bmpInfoH.bfType = ('M' << 8 | 'B'); bmpInfoH.bfReserved1 = 0; bmpInfoH.bfReserved2 = 0; ar.Write(&BmpFileH,sizeof(BmpFileH)); ar.Write(&bmpInfoH,sizeof(bmpInfoH)); //here I need to write the byte them self... but bm.bmBits are always NULL ar.Write(bm.bmBits,bm.bmWidthBytes); //destroying... CBitmapDC.SelectObject(OldBitMap); delete bitmapbitstemp;
}
else
{
// TODO: add loading code here
}
}BitMapTemp.Serialize(ar); //do not work... any help will be fine... Remi Morin Rmorin@Operamail.com Remi.Morin@Lyrtech.com
-
in my Document class the function serialize... I wan,t to save my data as a monochrome bitmap so I do
void CWoopDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
//I need a bitmap object
CBitmap BitMapTemp;
//a device context to draw on it
CDC CBitmapDC;
CBitmap* OldBitMap;//initialisation of the dc CBitmapDC.CreateCompatibleDC(NULL);
//here I'm not sure of that... I guess
//I create an array of bytes for the bitmap void \* bitmapbitstemp = malloc( Size\_X\*Size\_Y / sizeof(BYTE)); //here I create the bitmap BitMapTemp.CreateBitmap(Size\_X,Size\_Y,1,1,bitmapbitstemp); //I send my bitmap to the DC and save the old one OldBitMap = CBitmapDC.SelectObject(&BitMapTemp); //(... I draw in it) //now I wan't to save it //I need a bitmapInfoHeader and A bitMap File Header BITMAPFILEHEADER BmpFileH; BITMAPINFOHEADER bmpInfoH; BITMAP bm; BitMapTemp.GetBitmap(&bm); //<--here I'm unable the get the bitmap bits, but the creation return true!!! BmpFileH.biBitCount = bm.bmBitsPixel; BmpFileH.biCompression = BI\_RGB; BmpFileH.biHeight = bm.bmHeight; BmpFileH.biPlanes = bm.bmPlanes; BmpFileH.biWidth = bm.bmWidth; BmpFileH.biSizeImage = BI\_RGB; BmpFileH.biClrUsed = 0; BmpFileH.biClrImportant = 2; BmpFileH.biXPelsPerMeter = 0; BmpFileH.biYPelsPerMeter = 0; BmpFileH.biSize = sizeof(BmpFileH); bmpInfoH.bfOffBits = sizeof(bmpInfoH)+sizeof(BmpFileH); bmpInfoH.bfSize = bm.bmWidthBytes; bmpInfoH.bfType = ('M' << 8 | 'B'); bmpInfoH.bfReserved1 = 0; bmpInfoH.bfReserved2 = 0; ar.Write(&BmpFileH,sizeof(BmpFileH)); ar.Write(&bmpInfoH,sizeof(bmpInfoH)); //here I need to write the byte them self... but bm.bmBits are always NULL ar.Write(bm.bmBits,bm.bmWidthBytes); //destroying... CBitmapDC.SelectObject(OldBitMap); delete bitmapbitstemp;
}
else
{
// TODO: add loading code here
}
}BitMapTemp.Serialize(ar); //do not work... any help will be fine... Remi Morin Rmorin@Operamail.com Remi.Morin@Lyrtech.com
Are you sure you're drawing in the correct map? Using CBitMapDC->LineTo etc? It sounds as if there is nothing in BitMapTemp. Hope this helps, Bill