Click here to Skip to main content
15,888,158 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
how to load image in C++?
Posted
Updated 19-May-10 4:59am
v2

hi baby
have a good time
i'm iranian like you!
well if you load and display that in mfc class(dialog) you shoud do these:

1st:
load atlimage.h for using the CImage,that's really usefull.
#iclude "atlimage.h"

2nd:
define a global CImage.you shoud define that before OnInit function.
CImage image1;

3th:
well you defined that and you can use that in a function like OnPaint;
at first we must load picture from hard :
bool OnInit(){
i.Load(_T("C:\a.jpg"));
}


4th:
and now you must draw that in form(dialog):

bool OnPaint(){
CClientDC dc(this);
image1.BitBlt(dc.m_hDC,0,0,SRCCOPY);
}


good luck baby


my email is: mahdiacuransx@yahoo.com
 
Share this answer
 
Comments
Chandrasekharan P 23-Jun-11 4:52am    
Nice... well explained. My 5
What do you mean with load image in C++?
You should be more specific to get a good answer; however, if you are using MFC or ATL and you want to load an image from file and then render it on screen (or printer), you should use the class CImage (declared in atlimage.h) which has appropriate methods to load, save and render images (it can handle the most common image file formats, like bmp, png, jpeg and so on).
 
Share this answer
 
Comments
taghit 21-May-10 7:00am    
I want display a picture from hard drive on the monitor.
can you help me???????????
Under C++ .NET:

Create a bitmap image object, passing it the desired filename:

Bitmap^ MyImage= new Bitmap("MyImage.bmp");

To draw it, use the Graphics of the event passed to you in the Paint event handler of the drawing window:

e->Graphics->DrawImage(MyImage);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900