CC++Introduction to C++Language FeatureLearn C++

How To Display An Image In A C++ Program and in A C Program

How To Display An Image In A C++ Program and in A C Program

The C/C++ programming language is one of the most popular programming languages in the world. C is a procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. C is one of the fastest languages to operate on images, we can use text forms and we can print images by plotting pixels or by changing pixels of a bitmap. C++ Builder is a powerful C++ Code Editor that you can also use to create C apps. Your C++ Builder apps can have modern libraries like the VCL and FMX libraries to display and manipulate different types of images that code may run in different operating systems.

There are many options to display Images in C++. I think the best and easy way to display image in C++ Builder is using TImage and loading an image into it.

How to display image in C++ program using C++ Builder ?

In C++ Builder there is a great TBitmap class in VCL and TBitmap class in FMX libraries that allows you load, save, display, analyze and modify images easily. It supports bmp, png, jpg, and some other image formats.

TBitmap is an encapsulation of a bitmap. A TBitmap is a powerful graphics object used to create, manipulate and store images in memory and as files on a disk. TBitmap contains an internal image of the bitmap graphic and automatically manages realization of the palette when drawn. It also has an internal Canvas. A TBitmap can be created from a stream or a file specified by name using CreateFromStream and CreateFromFile. The image contained by the current TBitmap can be loaded or saved from or to specified streams or files. For a list of formats supported by each platform, see TBitmapCodecManager.

We can use TImage to display images and we can load an image by using LoadFromFile() method in C++ Builder FMX applications as below,

Here is an example how to use TBitmap in FMX application,

Here are more Bitmap examples,

How to display image in C program using graphics library?

In some applications, you may be using old compilers that may require this graphics library. It has been may be 20 or 30 years that I haven’t used graphics library in my applications. In some C++ compilers ( mostly old ones may have graphics.h ) and IDE’s which are using MinGW and GNU C/C++ compiler you can use graphics.h library. You can download graphics.h library for C application from here : https://github.com/SagarGaniga/Graphics-Library/blob/master/graphics.h or you can download it from from http://winbgim.codecutter.org/ 

Here is a very simle example to display a bitmap using graphics.h,

As you see you we can use the readimagefile() function of graphics library to display images. Here is the definition of the readimagefile() function.

How to display image in C program using OpenCV?

In C and C++ you can use OpenCV library to display images. The Intel Image Processing Library(IPL) has a IplImage which is a structure to point data that contains the image elements like size, number of channels, etc. It has a pointer called IPL image header. Thus, we can allocate an image to this via cvLoadImage() function as below,

How to display image in C program using GTK?

In GNU C / C++ we can use GTK library to display images. Simply you can use gtk_image_new_from_file() function to load an image to a GtkWidget as below,

GTK Image has been explained as here officially by gtk.org. We can use gtk_new_image_from_file() function to load image.

How to display image in C program in a text form?

In console applications you can use ASCII characters to display images. This is a very old method but still we are using to have fun in some examples. Here are the two great examples that shows how you can use to display Mandelbrot in 2D and a 3D donut amazingly.

Although the free C++ Builder Community Edition is extremely powerful it is intended for students, beginners, and startups. If you are a regular business or do not qualify for the free community edition then you can download a free trial of the very latest full RAD Studio C++ Builder version.

How To Display An Image In A C++ Program and in A C Program the C++ logo

C++ Builder is the easiest and fastest C and C++ IDE for building everything from simple to professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder an

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?