Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Application crashes only in release mode (possible heap/stack corruption) Pin
Rajesh R Subramanian9-Dec-10 17:26
professionalRajesh R Subramanian9-Dec-10 17:26 
AnswerRe: Application crashes only in release mode (possible heap/stack corruption) Pin
XTAL25612-Dec-10 12:09
XTAL25612-Dec-10 12:09 
QuestionC Casting Problem Pin
Andy2029-Dec-10 8:14
Andy2029-Dec-10 8:14 
AnswerRe: C Casting Problem Pin
Luc Pattyn9-Dec-10 9:01
sitebuilderLuc Pattyn9-Dec-10 9:01 
GeneralRe: C Casting Problem Pin
Andy2029-Dec-10 10:41
Andy2029-Dec-10 10:41 
GeneralRe: C Casting Problem [modified] Pin
Luc Pattyn9-Dec-10 11:06
sitebuilderLuc Pattyn9-Dec-10 11:06 
AnswerRe: C Casting Problem Pin
mbue9-Dec-10 12:07
mbue9-Dec-10 12:07 
QuestionSave image from picturebox use MFC Pin
josipahutar9-Dec-10 8:02
josipahutar9-Dec-10 8:02 
hi guys,,,
i'm a newbie in MFC so i'm need your advice to complete final project about identification signature. in this time i have problem about how to save image from picture box in MFC. this is my code used in MFC. this code not save image from picturebox. what's wrong with my code???


void SaveBitmapToFile( BYTE* pBitmapBits, LONG lWidth, LONG lHeight,WORD wBitsPerPixel, LPCTSTR lpszFileName );

void CSaveimageDlg::OnSave()
{
// TODO: Add your control notification handler code here
CDC *pDC = m_pic1.GetDC();
CDC dcMem1;
CRect rect;
m_pic1.GetClientRect(rect);
HDC hdc;
HBITMAP hBitmap = NULL;
BITMAP bm;

CBitmap Bitmap;
m_pic1.SetBitmap(Bitmap);
Bitmap.CreateBitmap(200 ,200,1,24,NULL);
m_bmpBitmap.GetBitmap(&bm);
//Bitmap.GetBitmap(&bm);
Bitmap.GetObject( sizeof( BITMAP ), &bm );

unsigned char *pData = new unsigned char [bm.bmHeight*bm.bmWidthBytes];
SaveBitmapToFile(pData,bm.bmHeight,bm.bmWidth,24,(LPCTSTR)_T("a.bmp"));
delete []pData;
}

void CSaveimageDlg::SaveBitmapToFile(BYTE *pBitmapBits, LONG lWidth, LONG lHeight, WORD wBitsPerPixel, LPCTSTR lpszFileName)
{
BITMAPINFOHEADER bmpInfoHeader = {0};
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biBitCount = wBitsPerPixel;
bmpInfoHeader.biClrImportant = 0;
bmpInfoHeader.biClrUsed = 0;
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biHeight = lHeight;
bmpInfoHeader.biWidth = lWidth;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biSizeImage = lWidth* lHeight * (wBitsPerPixel/8);

BITMAPFILEHEADER bfh = {0};
bfh.bfType=0x4D42;
bfh.bfType = 'B'+('M' << 8);
bfh.bfOffBits = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER);
bfh.bfSize = bfh.bfOffBits + bmpInfoHeader.biSizeImage;

HANDLE hFile = CreateFile( lpszFileName,GENERIC_WRITE, 0,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);

if( !hFile ) // return if error opening file
{
return;
}

DWORD dwWritten = 0;
WriteFile( hFile, &bfh, sizeof(bfh), &dwWritten , NULL );
WriteFile( hFile, &bmpInfoHeader, sizeof(bmpInfoHeader), &dwWritten, NULL );
WriteFile( hFile, pBitmapBits, bmpInfoHeader.biSizeImage, &dwWritten, NULL );
CloseHandle( hFile );
}
AnswerRe: Save image from picturebox use MFC Pin
mbue9-Dec-10 12:16
mbue9-Dec-10 12:16 
GeneralRe: Save image from picturebox use MFC Pin
tagopi9-Dec-10 17:08
tagopi9-Dec-10 17:08 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar11-Dec-10 7:27
josipahutar11-Dec-10 7:27 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar11-Dec-10 7:38
josipahutar11-Dec-10 7:38 
GeneralRe: Save image from picturebox use MFC Pin
tagopi12-Dec-10 17:08
tagopi12-Dec-10 17:08 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar13-Dec-10 7:29
josipahutar13-Dec-10 7:29 
GeneralRe: Save image from picturebox use MFC Pin
tagopi16-Dec-10 16:45
tagopi16-Dec-10 16:45 
Question890918 - keystroke seems not to generate the desired command Pin
ilostmyid29-Dec-10 6:45
professionalilostmyid29-Dec-10 6:45 
AnswerRe: 890918 - keystroke seems not to generate the desired command Pin
mbue9-Dec-10 12:25
mbue9-Dec-10 12:25 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
ilostmyid210-Dec-10 3:53
professionalilostmyid210-Dec-10 3:53 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
mbue10-Dec-10 8:59
mbue10-Dec-10 8:59 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
ilostmyid219-Dec-10 0:38
professionalilostmyid219-Dec-10 0:38 
Questionfull path of a process Pin
zon_cpp8-Dec-10 23:46
zon_cpp8-Dec-10 23:46 
AnswerRe: full path of a process PinPopular
CPallini9-Dec-10 0:12
mveCPallini9-Dec-10 0:12 
GeneralRe: full path of a process [modified] Pin
zon_cpp9-Dec-10 0:28
zon_cpp9-Dec-10 0:28 
QuestionRe: full path of a process Pin
CPallini9-Dec-10 0:37
mveCPallini9-Dec-10 0:37 
AnswerRe: full path of a process Pin
zon_cpp9-Dec-10 0:41
zon_cpp9-Dec-10 0:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.