CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Join Date
    Jun 1999
    Posts
    505

    [RESOLVED] Displaying a jpeg image

    Hi,
    Can somebody guide me which command should i use for displaying a jpeg image in Visual Studio 2008 (VC++)?In the past i used LoadImage function for displaying Bitmaps. Some body plz guide me.

    Zulfi.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    You could use CImage class.
    Or GDI+
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Displaying a jpeg image

    The oldi-goldi way is OleLoadPicture, but it is only aware of BMP and JPEG formats.
    Sample: HOWTO_oleloadpicture_with_jpeg_file.zip

    ATL::CImage class Victor mentioned is much more universal, but not available in VC Express versions.
    Sample: HOWTO_load_bitmap_to_stream_and_obtain_handle.zip

    GDI+ API is actually what CImage wraps around. A big deal is it is free and multiformat.
    Sample: HOWTO_display_JPEG_from_resource.zip

    Intel IPP includes image processing features, but you have to buy a license. It supports a wide variety of formats.

    libjpeg is open source library, and therefore it's free, but it is about JPEG only.
    Last edited by Igor Vartanov; March 21st, 2014 at 04:26 AM.
    Best regards,
    Igor

  4. #4
    Join Date
    Jun 1999
    Posts
    505

    Re: Displaying a jpeg image

    Hi,
    Thanks for your response. I understand some portion of the code which I used to load bitmap image. Most of the stuff is related to windows programming. Any way thanks for your help on this. I have tried to find the example related to CImage class. I have found one example but its not displaying the image on the screen.
    Code:
    
    void CRotateImageView::OnDraw(CDC* pDC)
    {
    	CRotateImageDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
    	CString szStr;
    	szStr= "D:\\image\\after_cut2.jpeg";
    	img.Load(szStr);
    	
    	// TODO: add draw code for native data here
    }
    & in *view.h

    Code:
    #include "atlimage.h"
    #include "atltypes.h" 
    
    :
    :
    
    public:
    	CRotateImageDoc* GetDocument() const;
            CImage img;
    :
    :
    };
    Somebody plz guide me.

    Zulfi.
    Last edited by Zulfi Khan2; March 21st, 2014 at 01:12 PM.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    The code you posted only loads the image. You have to write also code to display it!
    Try the CImage::Draw method.
    Victor Nijegorodov

  6. #6
    Join Date
    Jun 1999
    Posts
    505

    Re: Displaying a jpeg image

    Hi,
    Thanks for your information. I tried the following code:
    Code:
    void CRotateImageView::OnDraw(CDC* pDC)
    {
    	CRotateImageDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
    	CString szStr;
    	szStr= "D:\\image\\after_cut2.jpeg";
    	img.Load(szStr);
    	CRect m_ShowDRect;
    	m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
    	SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
    	img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
    	
    }
    I am getting following error:

    imageview.cpp(111) : error C3861: 'SetScrollSizes': identifier not found
    If i remove SetScrollSizes it gives me a Debug Assertion Failed Message:
    File: C:\Program files (x86)\microsoft visual Studio 9.0\vc\atimfc\include\atImage.h
    Line: 905
    Expression: m_hBitmap!=0

    Kindly guide me.

    Zulfi.
    Last edited by Zulfi Khan2; March 22nd, 2014 at 07:47 AM.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    SetScrollSizes is a method of SetScrollSizes class.
    What is the class you have derived your CRotateImageView from?

    Besides, why do you call it in OnDraw handler? The same question - about loading an image. Why not to do it once somewhere in OnInitialUpdate?
    Victor Nijegorodov

  8. #8
    Join Date
    Jun 1999
    Posts
    505

    Re: Displaying a jpeg image

    Hi,
    Thanks for your response. I am calling it in OnInitialUpdate( ) but its still giving me same Debug Assertion Failed message (without CScrollSizes).
    Code:
    void CRotateImageView::OnInitialUpdate()
    {
    	
    	CView::OnInitialUpdate();
    	CDC* pDC;
    	pDC=NULL;
    	CString szStr;
    	szStr= "D:\\image\\after_cut2.jpeg";
    	img.Load(szStr);
    	CRect m_ShowDRect;
    	m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
    	CScrollView::SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
    	img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
    	// TODO: Add your specialized code here and/or call the base class
    }
    If I use CScrollSizes then it gives me following error:


    1>------ Build started: Project: RotateImage, Configuration: Debug Win32 ------
    1>Compiling...
    1>RotateImageView.cpp
    1>d:\zulfi\vcprog\vc2008\rotateimage\rotateimage\rotateimageview.cpp(127) : error C2352: 'CScrollView::SetScrollSizes' : illegal call of non-static member function
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(4364) : see declaration of 'CScrollView::SetScrollSizes'
    1>Build log was saved at "file://d:\Zulfi\VCProg\VC2008\RotateImage\RotateImage\Debug\BuildLog.htm"
    1>RotateImage - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Kindly guide me.

    Zulfi.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    Quote Originally Posted by Zulfi Khan2 View Post
    Hi,
    Thanks for your response. I am calling it in OnInitialUpdate( ) but its still giving me same Debug Assertion Failed message (without CScrollSizes).
    Code:
    void CRotateImageView::OnInitialUpdate()
    {
    	
    	CView::OnInitialUpdate();
    	CDC* pDC;
    	pDC=NULL;
    	CString szStr;
    	szStr= "D:\\image\\after_cut2.jpeg";
    	img.Load(szStr);
    	CRect m_ShowDRect;
    	m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
    	CScrollView::SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
    	img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
    	// TODO: Add your specialized code here and/or call the base class
    }
    This code is wrong and does not make anz sense!
    1. You must draw only in response to WM_PAINT message that means (for CView derived classes) - withiin OnDraw() method.
    2. You did not answer my question about the class you have derived your CRotateImageView from.


    Quote Originally Posted by Zulfi Khan2 View Post
    If i remove SetScrollSizes it gives me a Debug Assertion Failed Message:
    File: C:\Program files (x86)\microsoft visual Studio 9.0\vc\atimfc\include\atImage.h
    Line: 905
    Expression: m_hBitmap!=0
    It sounds that your image was not loaded. What is the return value of
    Code:
    img.Load(szStr);
    Victor Nijegorodov

  10. #10
    Join Date
    Jun 1999
    Posts
    505

    Re: Displaying a jpeg image

    Hi,
    Its derived from CView.
    Code:
    class CRotateImageView : public CView
    {
    protected: // create from serialization only
    	CRotateImageView();
    	DECLARE_DYNCREATE(CRotateImageView)
    
    // Attributes
    public:
    	CRotateImageDoc* GetDocument() const;
        CImage img;
    
    
    // Operations
    public:
    :
    :
    };
    I cant tell you the return value because debugger is not working (Debug-> Start Debugging: it runs to completion and does not 'run to cursor' instead)and MessageBox command is also giving an error which i have posted in another thread. Kindly guide me how to find the return value.

    Zulfi.

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Displaying a jpeg image

    Quote Originally Posted by Zulfi Khan2 View Post
    szStr= "D:\\image\\after_cut2.jpeg";
    Are you sure the file exists and really is JPEG?

    Quote Originally Posted by Zulfi Khan2 View Post
    I am getting following error: imageview.cpp(111) : error C3861: 'SetScrollSizes': identifier not found
    SetScrollSizes is a member of CScrollView, so your view class must inherit to the class. You must not blindly copy-paste just a few lines having no idea how actually it works.
    Best regards,
    Igor

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    1. If you derived your class from from CView than you cannot use CScrollView::SetScrollSizes. Period.
    BTW, why did you derive from CView rather than CScrollView?
    2. Try to rebuild the project. (rebuild all)
    3. change your code to
    Code:
    HRESULT hr = img.Load(szStr);
    to see the return value in the watch window.
    4. Search for some CImage examples like
    http://forums.codeguru.com/showthrea...e-CImage-class
    http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx
    Victor Nijegorodov

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Displaying a jpeg image

    Quote Originally Posted by Zulfi Khan2 View Post
    Kindly guide me how to find the return value.
    Load() is a function. Now you tell me how to find the return value of a function. If you don't know that, it is time for you to get back to school bench and learn C++ basics.
    Best regards,
    Igor

  14. #14
    Join Date
    Jun 1999
    Posts
    505

    Re: Displaying a jpeg image

    Hi,
    Thanks for your time, efforts and suggestions. Still I am getting Debug Assertion Failed message at Line 905 same as i wrote earlier (Post#8). I am now using CScrollView as the base class. There is no problem with SetScrollViewSizes.
    My code is:

    Code:
    void CRotateImageScrollView::OnDraw(CDC* pDC)
    {
    	CRotateImageScrollDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
       
    
    	
    	CString szStr,szstr1;
    	szStr= "D:\\images\\after_cut2.jpeg";
    	HRESULT hr=img.Load(szStr);
        
    	CRect m_ShowDRect;
    	m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
    	SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
    	img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
    	// TODO: add draw code for native data here
    }
    Thanks for your guidance i found that path was not correct.

    Printing integer values is a difficult task in VC. I am still trying with your links.

    Zulfi.
    Last edited by Zulfi Khan2; March 23rd, 2014 at 03:23 AM.

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Displaying a jpeg image

    Quote Originally Posted by Zulfi Khan2 View Post
    Still I am getting Debug Assertion Failed message at Line 905 same as i wrote earlier (Post#8)..
    it is because your image was not loaded.

    Quote Originally Posted by Zulfi Khan2 View Post
    Printing integer values is a difficult task in VC.
    No. It is very very easy!
    Code:
    int n = 264372643;
    CString s;
    s.Format(_T("n = %d"), n)
    // now you have a string a can pass it in the AfxMessageBox or in some control;
    Note that you do NOT need to print your integer here.
    Instead you have to debug your code and look at the "Watch" window to see all available variable values.
    Victor Nijegorodov

Page 1 of 3 123 LastLast

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