Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MFC: How to display an image in a view

Posted on 2010-11-23
7
Medium Priority
?
587 Views
Last Modified: 2012-06-22
Dear experts,

I have an MFC program that displays lines of text in a view. But I would need to display pictures besides the text. Is there any simple way to do that?

Thanks.
0
Comment
Question by:tantormedia
7 Comments
 
LVL 4

Expert Comment

by:incerc
ID: 34196958
0
 
LVL 5

Expert Comment

by:Xper4net
ID: 34197004
It can be done in virtual OnDraw. But then, difficulty level depends on image type. If this is a bmp, no concern. If you want to display a jpg or a gif, there's no standard function, you must use an external library.
0
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 1000 total points
ID: 34198151
If you need to read a JPEG, GIF, orBMP, you can use the MFC class CImage.  
However, CImage uses GDI+.  That means the resulting application won't run on a Windows operating systems that pre-dates XP without downloading some sort of an update.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tantormedia
ID: 34198404
How about PNG?
0
 
LVL 5

Assisted Solution

by:Xper4net
Xper4net earned 1000 total points
ID: 34198489
@HooKooDooKu : you're right...I've forgotten CImage improvements.

Then, solution should be:
class CMyView : public CView
{
protected: // create from serialization only
	CMyView();
	DECLARE_DYNCREATE(CMyView)

// Overrides
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
// Implementation
public:
	virtual ~CMyView();
// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

 CImage m_Image ;
};

CMyView::CMyView()
{
    m_Image.Load("myImage.jpg") ;
}

void CMyView::OnDraw(CDC* /*pDC*/)
{
   m_Image.Draw(pDC->GetSafeHdc(), 0, 0) ; // consider overrides if you want to stretch image
}

Open in new window

0
 
LVL 5

Expert Comment

by:Xper4net
ID: 34198496
CImage handles PNG
0
 

Author Closing Comment

by:tantormedia
ID: 34199064
Thank you very much.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question