Display image in Visual C++ console application?

5.2k Views Asked by At

How can we display image in visual C++ console application? The image format can be of any types like bmp, jpeg, tiff, and so on. I want to open a new window and display the image in that window. I don't want to use others' libraries like openCV and so on. Thanks!

2

There are 2 best solutions below

2
On

The console is a text-based environment and it won't be possible to display jpgs/bmp. You need to use a GUI library that creates windows (like WPF if you're using Windows) to display images.

You're already using others' libraries by using C++ and the console. Using libraries is what programming is all about.

You can actually open a WPF window from console application using this: How to start the WPF window from console programmatically?

6
On

You can very easily, trivially, display an image from any Windows application.

For example, you can use the C++ library's system function to launch mspaint.exe with the image you want. Or you can use an API function such as ShellExecute to launch an image file in the viewer that's associated with the filename extension.

In a console application system is particularly nice since you avoid an extra console window popping up.

Displaying an image directly in a console window is a different kettle of fish, so technically challenging that one may as well say it's practically impossible.

That has nothing to do with the application having console or GUI subsystem, but with the fact that a console window is managed for you, as I recall by a different dedicated process.

What you can do if you want that effect (which was strongly indicated by the original question), is to put a borderless window on top of the console window. Maybe, if that works, make the console window owner. But you want to move that on-top window along with the console window, which I would guess involves some complexity.