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