VC++ - Save modified image into bmp file.

I need to save a modified image which is being displayed in a window. I am  using VC++ 6.0.

The image is loaded from a bmp file and displayed in a child window. Using the device context, I inserted some text into the image.

My problem is how do I save this image together with the text shown in this child window into a bmp file?

Or is there any way that I can write the text straight into the image bits?

I prefer the solution to the first question.

Who is Participating?
basantConnect With a Mentor Commented:
  CDC dcStretchMem;
      if(! dcStretchMem.CreateCompatibleDC(&m_dcMem))
            MessageBox("Can't Create Compatible DC","Message",MB_OK);
      CBitmap bmpPrint;
      if(! bmpPrint.CreateCompatibleBitmap(&m_dcMem,nWidth,nHeight))
            MessageBox("Can't Create Compatible Bitmap","Message",MB_OK);
      CBitmap* pbmpOld = dcStretchMem.SelectObject(&bmpPrint);
            MessageBox("Can't Select Bitmap","Message",MB_OK);
      if(! dcStretchMem.StretchBlt(0,0,nWidth,nHeight,&m_dcMem,
            MessageBox("Can't Stretch Bitmap","Message",MB_OK);
      BOOL bRetVal = pDC->BitBlt(nStartX,nStartY,nWidth,nHeight,&dcStretchMem,


You create a Memory Device context and create a compatible bitmap. Then Call StretchBlt or BitBlt to that Device then store the Bitmap in File.
Use GetBitmapBits for that.
All Courses

From novice to tech pro — start learning today.