how to do binary file to image(bmp etc) conversion in c++

I have ultrasonic data from sensor available from my sensor and save as in a binary file xxx.bin I want to make an image from this file but unable to find the solution. After loads of search I come up with QT libraries, windows MFC etc.

Note that this binary file is just a simple raw data from my FPGA device. I need to make the image out of it. I have a program in LabVIEW that can do it, but now I have to make my system in C++ completely

any other idea would be appreciable


Here is one way to do it.

Write the bytes to a simple image file and save as PGM image format. You can use GIMP software to view this image.

FILE *pFp = fopen("image.pgm", "wb");

int width = // get the width of the image ;
int height = // get the height of the image ;

UCHAR * start =  // get the starting location of the image data ;
if (pFp)
    //header of the pgm file
    fprintf(pFp, "P5\n%d\n%d\n%d\n", width, height, 255);
    for (int i = 0; i < height*width; i++)

Need Your Help

Why can't sed replace 0x24 byte in binary file?

replace sed binary hex binaryfiles

I'm want to replace some bytes in binary file to another.

How to post JSON data using curl over basic http auth?

api rest curl

I want to post data using curl unix command what I got by googling is doing like below: