CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Posts
    6

    Display an image in Gui

    I got the image path from the file directory using the dlgOpen.GetPathName() function and it is saved to a char array eg path.I need to display it on Gui ,better on a new Dialog box.This image may be bmp or jpg.

    Help required

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: Display an image in Gui

    You can use OleLoadPicture() look at this sample from MSDN: How to load graphics files and display them in Visual C++

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Display an image in Gui

    for bmp you dont need any coding. just draw a picture control on your dialog from resource editor in vc++ and add a bmp, you are done.

    for jpg you need to use some functions such as OleLoadPicturePath() ie using some COM api. If you want I can provide you some code snippet
    ◄◄ hypheni ►►

  4. #4
    Join Date
    Sep 2010
    Posts
    6

    Re: Display an image in Gui

    Sample code is helpful

  5. #5
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Display an image in Gui

    bmp load should be easiest one to display image on dialog. anyways the way to load jpg is here.

    Code:
    	IPicture *m_pic = NULL;
    	RECT rc;
    	CDC *pdc = NULL;
    	long hmWidth;
    	long hmHeight;
    	
    	::OleLoadPicturePath(L"your_jpg_file", NULL, 0, 0, IID_IPicture, reinterpret_cast<void **>(&m_pic));
    
    	m_pic->get_Width(&hmWidth);
    	m_pic->get_Height(&hmHeight);
    
    	pdc = m_jpg.GetDC();
    	m_gif.GetClientRect(&rc);
    
    	m_pic->Render(pdc->m_hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 
    				0, hmHeight, hmWidth, -hmHeight, &rc);
    	m_pic->Release();
    
    	m_gif.ReleaseDC(pdc);
    m_jpg is the static picture control in which the image is being drawn.
    ◄◄ hypheni ►►

  6. #6
    Join Date
    Sep 2010
    Posts
    6

    Re: Display an image in Gui

    Thanks

  7. #7
    Join Date
    Sep 2010
    Posts
    6

    Re: Display an image in Gui

    But how change the height and width of the static control according to image height and width.For example 200 * 200 image ,the display also 200 * 200.for 64 * 64,the image also looks 64 *64.Now the problem is that the width and height on the dialog is same

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured