Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it possible to edit an image in hex format and then to open it as normal

I know that an image file contains not only pixels but also some other information about the file.

For example, a jpeg file always starts with FFDB FFE0.

I'm thinking if I can change a few of information in a jpeg file but it can be still opened as normal.

For example, imagine that there is a jpeg image file as below:

0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 
0x00, 0x01, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x84, 0x00, 0x09, 0x06, 0x07, 0x13, 0x13, 0x12, 0x13, 
0x13, 0x13, 0x13, 0x16, 0x15, 0x15, 0x17, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x17, 0x18, 0x17, 
0x1A, 0x16, 0x1F, 0x18, 0x1D, 0x17, 0x18, 0x17, 0x1A, 0x18, 0x18, 0x18, 0x1D, 0x28, 0x20, 0x1D, 
0x1A, 0x25, 0x1D, 0x17, 0x1A, 0x21, 0x31, 0x21, 0x25, 0x29, 0x2D, 0x2E, 0x2E, 0x2E, 0x17, 0x1F

If the first 0xFF is a thing that I can change, meaning that no matter what it is, this image file can be printed as normal, I may want to change it with another value.

So my question is: Is there something I can change in a jpeg file?

Also, here is my program about converting a jpeg to hex file:

int main(int argc, char **argv)
{
    Mat image;
    image = imread("test.jpg", 0);  
    for ( int i=0; i<image.total(); i++ )
    {
        cout << cv::format("0x%x ", image.at<uchar>(i)); // this prints hex numbers ( 0x40 for 64, etc)
    }

    return 0;
}

However, when I execute it, I get a file starting with 0x2f 0x30 0x30 0x32, how comes? I think all of jpg files should be started with 0xFF, 0xD8, 0xFF, 0xE0.