
- Forum
- Programming Talk
- C and C++
- Reading Binary Format Picture in C++
Reading Binary Format Picture in C++
This is a discussion on Reading Binary Format Picture in C++ within the C and C++ forums, part of the Programming Talk category; Can anyone help me to write the code for the following in C++: I need to read a pic present ...
-
12-16-2010, 11:42 PM #1
- Join Date
- Dec 2010
- Answers
- 32
Reading Binary Format Picture in C++
Can anyone help me to write the code for the following in C++:
I need to read a pic present in binary format. At present, you can see the pic as a matrix of 1 and 0. If we will read all 1's present in the matrix tracing in a proper manner, we can say what this alphabet is.
Suppose its A. Draw a matrix with 1's in such a position that it will make A and 0 in the remaining. How to code to read this A?
Last edited by admin; 03-20-2011 at 10:28 AM.
-
03-09-2011, 12:32 AM #2
Below is the program to read the binary format.. but first convert ur image binary format to .bin!!
and yes one more thing this program reads 1st 100 bytes in to hexadecimal so u can find it easy to figure ur text.
#include <stdio.h>
#include <iostream>
using namespace std;
typedef unsigned char BYTE;
// Get the size of a file
long getFileSize(FILE *file)
{
long lCurPos, lEndPos;
lCurPos = ftell(file);
fseek(file, 0, 2);
lEndPos = ftell(file);
fseek(file, lCurPos, 0);
return lEndPos;
}
int main()
{
const char *filePath = "C:\\Users\\UrName\\Desktop\\testFile.bin";
BYTE *fileBuf; // Pointer 2 d buffered data
FILE *file = NULL; // pointer
// Open d file in binary mode using d "rb" format string
if ((file = fopen(filePath, "rb")) == NULL)
cout << "Could not open specified file" << endl;
else
cout << "File opened successfully" << endl;
long fileSize = getFileSize(file);
fileBuf = new BYTE[fileSize];
// buffer read
fread(fileBuf, fileSize, 1, file);
// hexadecimal
for (int i = 0; i < 100; i++)
printf("%X ", fileBuf[i]);
cin.get();
delete[]fileBuf;
fclose(file);
return 0;
}
I hope this may help u.. if not then feel free to ask!! Man sometimes use a hex editor or MSVS 9 hex editor if u have a binary format to read!
see ya
Swapwarick

Reply With Quote





