drawing saving

hi all
i had make drawing on the dilaogs. now i want that these drawing should be saved in bmp file or the jpeg file tell me how to do that or any other place such as picturebox where i can draw ans save as bmp file.
[222 byte] By [tasleem] at [2007-11-19 19:32:07]
# 1 Re: drawing saving
You can draw to the bitmap at first and then save this bitmap to dib file or jpeg file,below are sample codes:

void GetBitmap(CBitmap &bmp, int cx, int cy,COLORREF crBack)
{
CDC dcScreen;
CDC dcMemNormal;
CDC dcMemBitmap;
CBitmap bmpNormal;
dcScreen.Attach(::GetDC(0));
dcMemNormal.CreateCompatibleDC(&dcScreen);
dcMemBitmap.CreateCompatibleDC(&dcScreen);

CSize szComp = GetDrawRect().Size();
szComp += CSize(4,4);
bmpNormal.CreateCompatibleBitmap(&dcScreen, szComp.cx + 1 , szComp.cy + 1);
dcMemNormal.SelectObject(&bmpNormal);

COLORREF crf = crBack;

CBrush brush;
brush.CreateSolidBrush(crf);
CRect rect(0,0,szComp.cx + 1, szComp.cy + 1);
dcMemNormal.FillRect(&rect,&brush);

PrepareDC(&dcMemNormal);
OnDraw(&dcMemNormal);
ClearDC(&dcMemNormal);

bmp.CreateCompatibleBitmap(&dcScreen, cx, cy);
dcMemBitmap.SelectObject(&bmp);

CRect rcFill(0,0,cx,cy);
dcMemBitmap.FillRect(&rcFill, &brush);

brush.DeleteObject();

int nDestCX = 0;
int nDestCY = 0;
double dRatio = 0;
if(szComp.cx > szComp.cy)
{
nDestCX = cx;
dRatio = (double)szComp.cy / (double)szComp.cx;
nDestCY = int((double)cy * dRatio);
}
else if(szComp.cx < szComp.cy)
{
nDestCY = cy;
dRatio = (double)szComp.cx / (double)szComp.cy;
nDestCX = int((double)cx * dRatio);
}
else
{
nDestCX = cx;
nDestCY = cy;
}
int nXOrigin = (cx - nDestCX) / 2;
int nYOrigin = (cy - nDestCY) / 2;

dcMemBitmap.StretchBlt(nXOrigin+1,nYOrigin+1,nDestCX-1,nDestCY-1,&dcMemNormal, 0,0,szComp.cx + 1, szComp.cy + 1, SRCCOPY);

dcScreen.Detach();
}

Hope it is useful,you can also consider to use other third party codes,such as XD++ MFC Library.

Cindy
-----------------------
For high quality flow/diagram MFC/C++ Visio Like visualization Source Code,download XD++ at:
http://www.ucancode.net
cindyonlyone at 2007-11-10 3:49:34 >
# 2 Re: drawing saving
If you're running on Win2k or XP, look into the GDI+ ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/gdi+/gdi+.asp). There is some support for saving bitmaps to these formats.

Viggy
MrViggy at 2007-11-10 3:50:35 >
# 3 Re: drawing saving
hi all
i had make drawing on the dilaogs. now i want that these drawing should be saved in bmp file or the jpeg file tell me how to do that or any other place such as picturebox where i can draw ans save as bmp file.

Please dont post the same question on different threads, you already asked it here (http://www.dev-archive.com/forum/showthread.php?t=379226).

Cheers
golanshahar at 2007-11-10 3:51:33 >