-
February 21st, 2004, 05:49 PM
#1
displaying a JPG-Image on a picture control
hello,
i am using the CImage class to display a picture on a picture control. The problem that i have is that the function Draw(...) from CImage only uses a CDC Pointer but i need the ID of the picture control to show there the picture that i loaded before with CImage::ReadFile(...). Can someone show me how i can manage this problem ?
thanx a lot
the code that i want to use is such as follow:
Code:
CString str = "C:\\Image\\LED_r.jpg";
CImage image;
image.ReadFile(str, CIMAGE_FORMAT_JPEG);
image.Draw(...
Last edited by Mike2003; February 21st, 2004 at 05:51 PM.
don't panic, TRY !!!
-
February 22nd, 2004, 11:17 AM
#2
Code:
CDC *pDC = GetDlgItem(IDC_PICTURE)->GetDC();
...
image.Draw(*pDC, ...);
GetDlgItem(IDC_PICTURE)->ReleaseDC(pDC);
gg
-
February 22nd, 2004, 05:39 PM
#3
thanx a lot but i trxied this subsequent code and it didn't work. Can you write me what i have done wrong ? (The code for )
Code:
BOOL CPictureDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
CString str = "C:\\Image\\LED_r.jpg";
m_pDC = GetDlgItem(IDC_PICTURE)->GetDC();
CImage image;
image.ReadFile(str, CIMAGE_FORMAT_JPEG);
image.Draw(m_pDC, 30,30,30,30);
return TRUE;
}
CPictureDlg::~CPictureDlg()
{
if(!m_pDC)
GetDlgItem(IDC_PICTURE)->ReleaseDC(m_pDC);
}
don't panic, TRY !!!
-
February 22nd, 2004, 05:43 PM
#4
Hi,
I am not definite on this, but I would assume you would need to place:
Code:
CString str = "C:\\Image\\LED_r.jpg";
m_pDC = GetDlgItem(IDC_PICTURE)->GetDC();
CImage image;
image.ReadFile(str, CIMAGE_FORMAT_JPEG);
image.Draw(m_pDC, 30,30,30,30);
Within the WM_DRAWITEM message handler; to try this go into your class wizard and select the WM_DRAWITEM message handler and then place this code in there.
I hope that this helps!
Best Regards,
Lea Hayes
-
February 22nd, 2004, 06:00 PM
#5
thank you but it still doesn't work. The picture-control remains empty :-(.
Code:
void CPictureDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CString str = "C:\\Image\\LED_r.jpg";
m_pDC = GetDlgItem(IDC_PICTURE)->GetDC();
CImage image;
image.ReadFile(str, CIMAGE_FORMAT_JPEG);
image.Draw(m_pDC, 10,10,40,40, 50, 50);
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Is maybe the problem on the subsequent code the DDX ? I have deactivated the DDX at the moment because i got an error when i compiled the code.
Code:
void CPictureDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPictureDlg)
//DDX_Control(pDX, IDC_PICTURE, m_imPicture);
//}}AFX_DATA_MAP
}
don't panic, TRY !!!
-
February 22nd, 2004, 06:07 PM
#6
Hi,
Have you enabled the "Owner Draw" property within the dialog editor, or if the button is created with code added the associated style upon the buttons creation?
For this to work you would need to do that.
Regards,
Lea Hayes
-
February 22nd, 2004, 06:13 PM
#7
hello,
do you mean the hack on the visible checkbox in the property box of the picture control ?
don't panic, TRY !!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|