Converting txt to bmp
-
Hi, Can anyone suggest a way to convert a text file to bmp at runtime:confused:, I was able to create and save the bitmap file but was unable to append text to it.:sigh:
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
-
Hi, Can anyone suggest a way to convert a text file to bmp at runtime:confused:, I was able to create and save the bitmap file but was unable to append text to it.:sigh:
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
Load (or create) the bitmap, select it into a memory DC and use DrawText or TextOut to draw your text onto the bitmap the same as you would draw text onto the screen DC. Select the bitmap out of the DC and save it.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
Load (or create) the bitmap, select it into a memory DC and use DrawText or TextOut to draw your text onto the bitmap the same as you would draw text onto the screen DC. Select the bitmap out of the DC and save it.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
already tried that but I don't see any text in the saved bmp file :confused:
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
Show your code.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
Show your code.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
CreateBitmap(); m_pMemDC = new CDC; VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) ); m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap ); CString str("This is a test message"); CPen cp; cp.CreatePen(PS_SOLID, 2,RGB(255,255,255)); CRect rect; GetClientRect(&rect); m_pMemDC->SelectObject(&cp); m_pMemDC->DrawText(str,str.GetLength(),rect,DT_LEFT); PBITMAPINFO pbi = getInfoStruct(m_Bitmap); CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); m_pMemDC->SelectObject(m_pOldBitmap);
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
-
CreateBitmap(); m_pMemDC = new CDC; VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) ); m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap ); CString str("This is a test message"); CPen cp; cp.CreatePen(PS_SOLID, 2,RGB(255,255,255)); CRect rect; GetClientRect(&rect); m_pMemDC->SelectObject(&cp); m_pMemDC->DrawText(str,str.GetLength(),rect,DT_LEFT); PBITMAPINFO pbi = getInfoStruct(m_Bitmap); CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); m_pMemDC->SelectObject(m_pOldBitmap);
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
Nilesh K. wrote: CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); I Believe, Such function doesn't exist in WIndow's Api!. could you show coding for that too, as your problem may be at the time of saving!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
Nilesh K. wrote: CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); I Believe, Such function doesn't exist in WIndow's Api!. could you show coding for that too, as your problem may be at the time of saving!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
CRect rect; CSize size; GetClientRect(&rect); size = rect.Size(); LPBITMAPINFO lpbi; // Fill in the BITMAPINFOHEADER lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))]; lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbi->bmiHeader.biWidth = size.cx; lpbi->bmiHeader.biHeight = size.cy; lpbi->bmiHeader.biPlanes = 1; lpbi->bmiHeader.biBitCount = 8; lpbi->bmiHeader.biCompression = BI_RGB; lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)size.cx * 8) * size.cy; lpbi->bmiHeader.biXPelsPerMeter = 0; lpbi->bmiHeader.biYPelsPerMeter = 0; lpbi->bmiHeader.biClrUsed = 0; lpbi->bmiHeader.biClrImportant = 0; // Fill in the color table UINT uUsage = DIB_RGB_COLORS; memcpy( lpbi->bmiColors, m_rgbPalette, sizeof(RGBQUAD) * 256 ); m_pWinDC = new CWindowDC(this); HBITMAP hBitmap = CreateDIBSection( m_pWinDC->m_hDC, lpbi, uUsage, (void **)&m_pBits, NULL, 0 ); delete [] (BYTE *)lpbi; ASSERT(hBitmap != NULL); m_Bitmap.Attach( hBitmap );
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
-
CRect rect; CSize size; GetClientRect(&rect); size = rect.Size(); LPBITMAPINFO lpbi; // Fill in the BITMAPINFOHEADER lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))]; lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbi->bmiHeader.biWidth = size.cx; lpbi->bmiHeader.biHeight = size.cy; lpbi->bmiHeader.biPlanes = 1; lpbi->bmiHeader.biBitCount = 8; lpbi->bmiHeader.biCompression = BI_RGB; lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)size.cx * 8) * size.cy; lpbi->bmiHeader.biXPelsPerMeter = 0; lpbi->bmiHeader.biYPelsPerMeter = 0; lpbi->bmiHeader.biClrUsed = 0; lpbi->bmiHeader.biClrImportant = 0; // Fill in the color table UINT uUsage = DIB_RGB_COLORS; memcpy( lpbi->bmiColors, m_rgbPalette, sizeof(RGBQUAD) * 256 ); m_pWinDC = new CWindowDC(this); HBITMAP hBitmap = CreateDIBSection( m_pWinDC->m_hDC, lpbi, uUsage, (void **)&m_pBits, NULL, 0 ); delete [] (BYTE *)lpbi; ASSERT(hBitmap != NULL); m_Bitmap.Attach( hBitmap );
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw