CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2004
    Posts
    32

    How to Display Images

    Hi,

    How can i show on a window an image, if it is tiff format/in jpg format,
    by opening through the file menu, like open dialog and selecting the file name i.e. either tiff/jpg file

    Thanking you

  2. #2
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: How to Display Images

    Also , pls. reference to this link : http://www.codeguru.com/Cpp/G-M/bitmap/.

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to Display Images

    Quote Originally Posted by sunny_sz
    Add the code snippet below into your event :
    Well...what is this code snippet supposed to do? Loading a JPEG as a bitmap? This will most-likely not work (at least I would be surprised if it would)?

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to Display Images

    Quote Originally Posted by ravirams
    How can i show on a window an image, if it is tiff format/in jpg format,
    by opening through the file menu, like open dialog and selecting the file name i.e. either tiff/jpg file
    Take a look at the following...

  5. #5
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: How to Display Images

    Thanks Andreas Masur's remind first . Maybe my misunderstand cause that I made a mistake .

    Just like you post , I think I already understood ravirams's meaning .

    In addition , I also want to attach my sample here , and I am sure that can works fine , and match to ravirams's requirments.
    Attached Files Attached Files

  6. #6
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: How to Display Images

    Code:
    CString	filename;
    TCHAR szFilters[] = _T("All Picture File(*.bmp,*.jpeg,*.jpg,*.gif,*.tiff)");
    CMyFileDialog dlg(TRUE,_T(""),_T("*.*"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,szFilters,AfxGetMainWnd());
    if (dlg.DoModal () == IDOK)
    {
    	filename = dlg.GetPathName();
    }
    else
    	{return;}
    CString szFilename;
    szFilename.Replace(".bmp",".jpeg");
    HBITMAP hBmp = (HBITMAP)::LoadImage(
    			0,
    			szFilename,
    			IMAGE_BITMAP,
    			0,
    			0,
    			LR_LOADFROMFILE|LR_CREATEDIBSECTION
    			);
    CDC *pDC;				
    pDC=GetDC();
    CBitmap     bmpHello;
    bmpHello.Attach(hBmp); 
    BITMAP bm;
    bmpHello.GetObject( sizeof(BITMAP), &bm );
    CDC         dcMem;
    dcMem.CreateCompatibleDC( pDC );
    CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
    pDC->BitBlt( 30,50, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );
    dcMem.SelectObject( pbmpOld );
    ReleaseDC( pDC );
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to Display Images

    Quote Originally Posted by Gunaamirthavelu
    Code:
    CString	filename;
    TCHAR szFilters[] = _T("All Picture File(*.bmp,*.jpeg,*.jpg,*.gif,*.tiff)");
    CMyFileDialog dlg(TRUE,_T(""),_T("*.*"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,szFilters,AfxGetMainWnd());
    if (dlg.DoModal () == IDOK)
    {
    	filename = dlg.GetPathName();
    }
    else
    	{return;}
    CString szFilename;
    szFilename.Replace(".bmp",".jpeg");
    HBITMAP hBmp = (HBITMAP)::LoadImage(
    			0,
    			szFilename,
    			IMAGE_BITMAP,
    			0,
    			0,
    			LR_LOADFROMFILE|LR_CREATEDIBSECTION
    			);
    CDC *pDC;				
    pDC=GetDC();
    CBitmap     bmpHello;
    bmpHello.Attach(hBmp); 
    BITMAP bm;
    bmpHello.GetObject( sizeof(BITMAP), &bm );
    CDC         dcMem;
    dcMem.CreateCompatibleDC( pDC );
    CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
    pDC->BitBlt( 30,50, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );
    dcMem.SelectObject( pbmpOld );
    ReleaseDC( pDC );
    I also fail to see how this code will load any other file than a bitmap...

  8. #8
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: How to Display Images

    sorry for the mistake.
    this code will display the image in Dialog Based appliction.
    Code:
    CString	filename;
    TCHAR szFilters[] = _T("All Picture File(*.bmp,*.jpeg,*.jpg,*.gif,*.tiff)");
    CMyFileDialog dlg(TRUE,_T(""),_T("*.*"),OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,szFilters,AfxGetMainWnd());
    if (dlg.DoModal () == IDOK)
    {
    	filename = dlg.GetPathName();
    }
    else
    	{return;}
    CString szFilename;
    szFilename.Replace(".jpeg",".bmp");
    HBITMAP hBmp = (HBITMAP)::LoadImage(
    			0,
    			szFilename,
    			IMAGE_BITMAP,
    			0,
    			0,
    			LR_LOADFROMFILE|LR_CREATEDIBSECTION
    			);
    CDC *pDC;				
    pDC=GetDC();
    CBitmap     bmpHello;
    bmpHello.Attach(hBmp); 
    BITMAP bm;
    bmpHello.GetObject( sizeof(BITMAP), &bm );
    CDC         dcMem;
    dcMem.CreateCompatibleDC( pDC );
    CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
    pDC->BitBlt( 30,50, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );
    dcMem.SelectObject( pbmpOld );
    ReleaseDC( pDC );
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  9. #9
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: How to Display Images

    Gunamirthavelu, the code u have presented will work for only bitmaps.

    To the OP. If you have time and patience to go through some code the following link will help you. It shows how to to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.

    CXIMAGE

    Edit:Sorry Andreas it seems I have provided the same link as you.
    Last edited by miteshpandey; January 9th, 2006 at 07:29 AM.
    If there is no love sun won't shine

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