-
March 20th, 2014, 01:16 PM
#1
[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.
-
March 20th, 2014, 01:31 PM
#2
Re: Displaying a jpeg image
You could use CImage class.
Or GDI+
Victor Nijegorodov
-
March 21st, 2014, 03:19 AM
#3
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
-
March 21st, 2014, 12:22 PM
#4
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.
-
March 21st, 2014, 01:23 PM
#5
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
-
March 22nd, 2014, 07:38 AM
#6
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.
-
March 22nd, 2014, 07:47 AM
#7
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
-
March 22nd, 2014, 11:01 AM
#8
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.
-
March 22nd, 2014, 11:20 AM
#9
Re: Displaying a jpeg image
Originally Posted by Zulfi Khan2
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.
Originally Posted by Zulfi Khan2
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
Victor Nijegorodov
-
March 22nd, 2014, 01:38 PM
#10
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.
-
March 22nd, 2014, 01:49 PM
#11
Re: Displaying a jpeg image
Originally Posted by Zulfi Khan2
szStr= "D:\\image\\after_cut2.jpeg";
Are you sure the file exists and really is JPEG?
Originally Posted by Zulfi Khan2
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
-
March 22nd, 2014, 01:52 PM
#12
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
-
March 22nd, 2014, 01:55 PM
#13
Re: Displaying a jpeg image
Originally Posted by Zulfi Khan2
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
-
March 23rd, 2014, 03:13 AM
#14
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.
-
March 23rd, 2014, 04:19 AM
#15
Re: Displaying a jpeg image
Originally Posted by Zulfi Khan2
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.
Originally Posted by Zulfi Khan2
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
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
|