Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
iam a beginner in c++. iam using visual studio 2008 professional. and i have to develop my project on win32 console application but i dont know what type of code is needed to load any kind of image on the console furthermore what will be the haeder files included and what are the limitations whether an image can be loaded on the console or not....plz guide me.
Posted
Comments
JackDingler 27-Feb-12 14:33pm    
What kind of images?

You cannot load images in console apps, you need to create a Windows app and use the various Bitmap functions to display images. You could start by adding a simple bitmap to the resources of your project and use LoadImage()[^].
 
Share this answer
 
Comments
JackDingler 27-Feb-12 14:33pm    
You can't 'display' images in the console of a console app.
But you can read them into memory.
Richard MacCutchan 27-Feb-12 14:38pm    
I understand that, but I am assuming OP wants to display them.
JackDingler 27-Feb-12 14:45pm    
I thought that at first, but the he/she says he/she must use a console application.

Perhaps we'll get some clarification...
Sergey Alexandrovich Kryukov 27-Feb-12 17:20pm    
The only problem here is: OP did not tell us what she/he wanted to do with images.
--SA
Sergey Alexandrovich Kryukov 27-Feb-12 17:20pm    
My 5, for now. :-)
--SA
I commonly load images from console apps. Performing operations such as deskewing and colour reduction.

It's also a trivial task to display 1 bit images in the console..

I gave-up on LoadImage a looong time ago - finding that the increased number of formats supported by GDI+ was worth the transition.


Every now and again I forget to initialize GDI+, and the app crashes upon startup. Otherwise, the following function performs adequetly for my needs.


C++
// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
   HBITMAP result=NULL;

   Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
   bitmap->GetHBITMAP(NULL, &result);
   delete bitmap;
   return result;
}


Before you use this function you must call the following init-code:
C++
static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
static ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);


Afterwards, you have to shut-down GDI+
C++
Gdiplus::GdiplusShutdown(gdiplusToken);



You'll need to include the gdiplus.h header file and link the gdiplus library
 
Share this answer
 
Comments
Member 8231285 28-Feb-12 9:11am    
can i load images if i use windows form application in visual studio 2008???
Member 8231285 28-Feb-12 9:11am    
if yes what will be the process or the code??
enhzflep 28-Feb-12 16:37pm    
Yes, of course you can!
I only ever use Visual Studio when I'm forced to, either for debugging or to build an MFC project. I wouldn't have a clue about how to _display_ the image in a c++ .net project, nor can I be bothered to find out (to be completely honest) - sorry.
I'd rather eat broken glass than use .NET (anything) for recreational programming. I learned ASM first and love it....

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