taodo112
asked on
help me
i want to load file bitmap:
event Button Open:
void CDrawing2BitmapDlg::OnBnCl ickedBopen ()
{
// TODO: Add your control notification handler code here
//xay dung bo loc cho open dialog
static char BASED_CODE szFilter[]= "Bitmap File (*.Bmp)|*.bmp||";
//tao hop hoi thoai open
CFileDialog m_ldFile (TRUE,".bmp",m_sBitmap,OFN _HIDEREADO NLY|OFN_OV ERWRITEPRO MPT,szFilt er);
//xem hop hoai thoi va lay ket qua
if (m_ldFile.DoModal()==IDOK)
{
//lay ten file duoc chon
m_sBitmap=m_ldFile.GetPath Name();
//tai file bitmap vao bo nho
//lay handle cua bitmap
HBITMAP hBitmap =(HBITMAP)::LoadImage(AfxG etInstance Handle(),m _sBitmap,I MAGE_BITMA P,0,0,LR_L OADFROMFIL E|LR_CREAT EDIBSECTIO N);
//ta da co gia tri handle cua bitmap
//kiem tra cac dieu kien cua handle
if (hBitmap)//neu chung ta da co handle
{
//xoa anh bitmap hien thoi dang luu
if(m_bmpBitmap.DeleteObjec t());
//neu co mot anh thi hay go no ra
m_bmpBitmap.Detach();
//gang anh muon xem vao Bitmap Object
m_bmpBitmap.Attach(hBitmap );
//vo hieu hoa control Image
}
}
}
function showbitmap:
void CDrawing2BitmapDlg::ShowBi tmap(CPain tDC* pdc,CWnd *pWnd)
{
CDrawing2BitmapDlg *lpWnd=(CDrawing2BitmapDlg *)pWnd;
BITMAP bm;
//lay bitmap da load
lpWnd->m_bmpBitmap.GetBitm ap(&bm);
CDC dcMem;
// tao device context de load bitmap vao
dcMem.CreateCompatibleDC(p dc);
CBitmap *pOldBitmap=(CBitmap*)dcMe m.SelectOb ject(lpWnd ->m_bmpBit map);
CRect lRect;
GetClientRect(lRect);
lRect.NormalizeRect();
pdc->StretchBlt(10,10,(lRe ct.Width() -20),(lRec t.Height() -20),&dcMe m,0,0,bm.b mWidth,bm. bmHeight,S RCCOPY);
dcMem.SelectObject(pOldBit map);
}
and in Onpaint:
void CDrawing2BitmapDlg::OnPain t()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBK GND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON );
int cyIcon = GetSystemMetrics(SM_CYICON );
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
CDrawing2BitmapDlg* pWnd=(CDrawing2BitmapDlg*) GetParent( );
if(pWnd)
{
ShowBitmap(&dc,pWnd);
CDialog::OnPaint();
//Draw();
}
}
}
i don't know wrong anywhere , i can't load bitmap
if you have a source about MFC , program can load, draw on bitmap loaded and save that bimap, thank you
event Button Open:
void CDrawing2BitmapDlg::OnBnCl
{
// TODO: Add your control notification handler code here
//xay dung bo loc cho open dialog
static char BASED_CODE szFilter[]= "Bitmap File (*.Bmp)|*.bmp||";
//tao hop hoi thoai open
CFileDialog m_ldFile (TRUE,".bmp",m_sBitmap,OFN
//xem hop hoai thoi va lay ket qua
if (m_ldFile.DoModal()==IDOK)
{
//lay ten file duoc chon
m_sBitmap=m_ldFile.GetPath
//tai file bitmap vao bo nho
//lay handle cua bitmap
HBITMAP hBitmap =(HBITMAP)::LoadImage(AfxG
//ta da co gia tri handle cua bitmap
//kiem tra cac dieu kien cua handle
if (hBitmap)//neu chung ta da co handle
{
//xoa anh bitmap hien thoi dang luu
if(m_bmpBitmap.DeleteObjec
//neu co mot anh thi hay go no ra
m_bmpBitmap.Detach();
//gang anh muon xem vao Bitmap Object
m_bmpBitmap.Attach(hBitmap
//vo hieu hoa control Image
}
}
}
function showbitmap:
void CDrawing2BitmapDlg::ShowBi
{
CDrawing2BitmapDlg *lpWnd=(CDrawing2BitmapDlg
BITMAP bm;
//lay bitmap da load
lpWnd->m_bmpBitmap.GetBitm
CDC dcMem;
// tao device context de load bitmap vao
dcMem.CreateCompatibleDC(p
CBitmap *pOldBitmap=(CBitmap*)dcMe
CRect lRect;
GetClientRect(lRect);
lRect.NormalizeRect();
pdc->StretchBlt(10,10,(lRe
dcMem.SelectObject(pOldBit
}
and in Onpaint:
void CDrawing2BitmapDlg::OnPain
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBK
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON
int cyIcon = GetSystemMetrics(SM_CYICON
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
CDrawing2BitmapDlg* pWnd=(CDrawing2BitmapDlg*)
if(pWnd)
{
ShowBitmap(&dc,pWnd);
CDialog::OnPaint();
//Draw();
}
}
}
i don't know wrong anywhere , i can't load bitmap
if you have a source about MFC , program can load, draw on bitmap loaded and save that bimap, thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER