displaying a JPG-Image on a picture control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: displaying a JPG-Image on a picture control

  1. #1
    Join Date
    Jul 2003
    Location
    Germany
    Posts
    54

    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 !!!

  2. #2
    Join Date
    Nov 2003
    Posts
    1,822
    Code:
        CDC *pDC = GetDlgItem(IDC_PICTURE)->GetDC();
        ...
        image.Draw(*pDC, ...);
        GetDlgItem(IDC_PICTURE)->ReleaseDC(pDC);
    gg

  3. #3
    Join Date
    Jul 2003
    Location
    Germany
    Posts
    54
    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 !!!

  4. #4
    Join Date
    Jan 2002
    Location
    United Kingdom
    Posts
    491
    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

  5. #5
    Join Date
    Jul 2003
    Location
    Germany
    Posts
    54
    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 !!!

  6. #6
    Join Date
    Jan 2002
    Location
    United Kingdom
    Posts
    491
    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

  7. #7
    Join Date
    Jul 2003
    Location
    Germany
    Posts
    54
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center