Click here to Skip to main content
15,898,857 members

Comments by Somnath T Avhad (Top 7 by date)

Somnath T Avhad 14-Jun-12 2:46am View    
So you mean to say for example:
I have created bitmap in VC++ and C# with following details :
Text = "TEST"
Font = "Bold"
Font Size = 20

So C# and VC++ bitmap my be different?
Somnath T Avhad 14-Jun-12 2:30am View    
No modifying C++ code is not required. we have application running in VC++ we are rewriting application in C#. so whatever bitpam data we get in VC++ i.e Byte array, we are expecting the same bitmap data in C#.
Somnath T Avhad 14-Jun-12 1:22am View    
I am adding VC++ code here.
void CTextBitmapWnd::CreateBitmapFromText(BYTE* pbByteArray,CString a_SMessage,CWindowsFontCDC* a_pWinFontCDC,int a_eHorizontalAllignment /*= E_INVALID_ALIGNMENT */ , bool a_bDrawVertical /*=FALSE*/ )
{
CString a_sMessage = a_SMessage;
int iMsgLen = a_sMessage.GetLength();

//int iMsgLen = 3;
if(0 == iMsgLen)
{
a_pWinFontCDC->m_uiBitmapDataSize = 0;
a_pWinFontCDC->m_BmpSize.cx = 0;
a_pWinFontCDC->m_BmpSize.cy = 0;

return;
}

m_sMessage = a_sMessage;
m_eHorizontalAllignment = a_eHorizontalAllignment;
m_bDrawVertical = a_bDrawVertical;

m_sMessage = AddCarriageReturn(m_sMessage);

CDC* pDC = GetDC();

CDC MemDC;
MemDC.CreateCompatibleDC( pDC );

CFont txtFont;
txtFont.CreateFontIndirect( &a_pWinFontCDC->m_winLogFont );
CFont* pOldFont = pDC->SelectObject( &txtFont );

int iPreviousExtraCharacters = pDC->GetTextCharacterExtra();
pDC->SetTextCharacterExtra(a_pWinFontCDC->m_uiCharacterPitch);

CalculateEndPoints(pDC, a_pWinFontCDC);
CRect rcTxt(0,0,m_szBitmap.cx, m_szBitmap.cy);

pDC->SelectObject( pOldFont );

int iImageSize = WIDTHBYTES(rcTxt.Width()) * rcTxt.Height();

int iTotalSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + iImageSize;

m_lpBmpInfo = (LPBITMAPINFO) new BYTE[iTotalSize];

memset( m_lpBmpInfo, 0, iTotalSize );

m_lpBmpInfo->bmiHeader.biBitCount = 1;
m_lpBmpInfo->bmiHeader.biClrImportant = 1;
m_lpBmpInfo->bmiHeader.biClrUsed = 2;
m_lpBmpInfo->bmiHeader.biCompression = BI_RGB;
m_lpBmpInfo->bmiHeader.biHeight = rcTxt.Height();
m_lpBmpInfo->bmiHeader.biWidth = rcTxt.Width();
m_lpBmpInfo->bmiHeader.biPlanes = 1;
m_lpBmpInfo->bmiHeader.biSize = sizeof(m_lpBmpInfo->bmiHeader);
m_lpBmpInfo->bmiHeader.biSizeImage = WIDTHBYTES(m_lpBmpInfo->bmiHeader.biWidth) * m_lpBmpInfo->bmiHeader.biHeight;

m_lpBmpInfo->bmiColors[0].rgbRed = m_lpBmpInfo->bmiColors[0].rgbGreen = m_lpBmpInfo->bmiColors[0].rgbBlue = 0;
m_lpBmpInfo->bmiColors[1].rgbRed = m_lpBmpInfo->bmiColors[1].rgbGreen = m_lpBmpInfo->bmiColors[1].rgbBlue = 255;

LPBYTE lpData = (LPBYTE)(m_lpBmpInfo + sizeof(BITMAPINFOHEADER));

m_hBitmap = (HBITMAP)::CreateDIBSection(pDC->GetSafeHdc(),m_lpBmpInfo, DIB_RGB_COLORS, (void**)&lpData, NULL, 0);

CBitmap messageBmp;
messageBmp.Attach( m_hBitmap );

iPreviousExtraCharacters = MemDC.GetTextCharacterExtra();
MemDC.SetTextCharacterExtra(a_pWinFontCDC->m_uiCharacterPitch);

CBitmap* pOldBmp = MemDC.SelectObject(&messageBmp);
pOldFont = MemDC.SelectObject( &txtFont );
COLORREF OldTextColor = MemDC.SetTextColor( RGB(255,255,255));
COLORREF OldTextBkColor = MemDC.SetBkColor( RGB(0,0,0));
MemDC.FillSolidRect(rcTxt, RGB(0,0,0));
DrawMessage(&MemDC, a_pWinFontCDC);

MemDC.SelectObject( pOldBmp );
MemDC.SelectObject( pOldFont );
CBitmap* pBitmap = new CBitmap();
pBitmap->Attach( messageBmp.Detach() );
messageBmp.DeleteObject();

DIBSECTION ds;
pBitmap->GetObject(sizeof(DIBSECTION), &ds);

a_pWinFontCDC->m_BmpSize.cy = ds.dsBm.bmHeight;
a_pWinFontCDC->m_BmpSize.cx = ds.dsBm.bmWidth;
a_pWinFontCDC->m_uiBitmapDataSize = WIDTHBYTES(ds.dsBm.bmWidth) * ds.dsBm.bmHeight;

//-----------------------------------------------------------------------------------------------------------------------
BITMAP Bmp;
pBitmap->GetBitmap( &Bmp );

iTotalSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2;
LPBITMAPINFO lpBmpInfo = (LPBITMAPINFO) new BYTE[iTotalSize];

lpBmpInfo->bmiHeader.biBitCount = 1;
lpBmpInfo->bmiHeader.biClrImportant = 1;
lpBmpInfo->bmiHeader.biClrUsed = 2;
lpBmpInfo->bmiHeader.biCompression = BI_RGB;
lpBmpInfo->bmiHeader.biHeight = Bmp.bmHeight;
lpBmpInfo->bmiHeader.biWidth = Bmp.bmWidth;
lpBmpInfo->bmiHeader.biPlanes = 1;
lpBmpInfo->bmiHeader.biSize = sizeof(lpBmpInfo->bmiHeader);
lpBmpInfo->bmiHeader.biSizeImage = WIDTHBYTES(lpBmpInfo->bmiHeader.biWidth) * lpBmpInfo->bmiHeader.biHeight;

lpBmpInfo->bmiColors[0].rgbRed = lpBmpInfo->bmiColors[0].rgbGreen = lpBmpInfo->bmiColors[0].rgbBlue =
Somnath T Avhad 14-Jun-12 1:13am View    
When I am using VC++ equivalent functions in C# , both should be identical.
That is the reason bitmap data is not indentical for bitmaps created in VC++ and C#.
Somnath T Avhad 14-Jun-12 1:11am View    
In C++ we are not creating any bitmap file on disk as such
everything is in memory.