How to convert a .bmp image into Byte array using C Program

amol saxena

I have a 1280 x 720 pixel .bmp file that I want to load into image2 that is declared like the following:

uint8_t *imageByte=NULL;

image2 is a file named home1.bmp

i want to read the bmp file and convert .bmp image to byte array imageByte which i will use for compare with home.bmp

I relatively new to c programming, so any one can tell me how should I being using to do so? thanks! This a part of my bmp image comparison code which will compare image1 with image2

# define BYTES_PER_PIXEL 4
# define BITMAP_HEADER 54
 int temp_width = 1280;
 int temp_height = 720;
 int temp_x = 0;
 int temp_y = 0;
 uint8_t k = 0;
 char* image1= "E:\\home.bmp";
 fp = fopen(image,"rb"); 
 fseek(fp, 0, SEEK_SET);
fseek(fp, BITMAP_HEADER, SEEK_SET);
for(temp_y=0; temp_y<temp_height; temp_y++)
{
    temp_x = 0; 

    for(temp_x=0; temp_x < (temp_width * BYTES_PER_PIXEL); temp_x++)
    {
        int read_bytes = fread(&k, 1, 1, fp);
        if(read_bytes != 0)
        {
            if(k != imageByte[temp_x])
            {

                printf("CompareImage :: failed \n");
                fclose(fp);

            }
        }
        else
        {
           printf("CompareImage :: read failed \n");
        }
    }
}
 printf("CompareImage :: passed \n");
George

As mentioned above, a BMP file starts with 1] A file header that gives information about the file like size ..etc 2] BMP information header that gives more information about the BMP properties These structures are of fixed size

The following link seems to be a perfect reference for you http://paulbourke.net/dataformats/bmp/

You should be able to get rid of byte by bytes comparison which is costly in most of the cases, just by reading the two header structured from the beginning and comparing. Do bytes by byte comparison only of the headers match.

Hope it helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert a .bmp image into Byte array using C Program

From Dev

c# How to convert pictureBox.Image to Byte Array?

From Dev

How to convert a byte-array to a Image in C#?

From Dev

c# How to convert pictureBox.Image to Byte Array?

From Dev

How to convert UIImagePicker image into a byte array objective-c

From Dev

ScalaFX: How to convert an Image object to a byte array

From Dev

How to convert byte array to buffered image

From Dev

How to convert Byte array into bitmap image?

From Dev

How to convert byte array to image in javascript

From Dev

ScalaFX: How to convert an Image object to a byte array

From Dev

How to convert a bitmap or byte array to an image?

From Dev

Convert byte array to Image

From Dev

Rotating a BMP image using C

From Dev

bind an image in c# using byte array

From Dev

How to convert raster byte array of an image to original image in java?

From Dev

convert byte array to image in Java using Google apps engine

From Dev

Convert PIL Image to byte array?

From Dev

Convert image to byte array quickly

From Dev

how to convert a byte[] to HttpPostedFileBase using c#

From Dev

How to Convert Byte Array to Image inside in Linq output List

From Dev

How can I convert a image into a byte array in uwp platform

From Dev

How to convert Bitmap image to byte array in wp7?

From Dev

How Can I Convert My new Byte Array To an Image

From Dev

how to convert BYTE array to char array for send with socket c++

From Dev

how to convert BYTE array to char array for send with socket c++

From Dev

How to create BitmapImage from a bmp file byte array?

From Dev

How to convert System.Byte[] into an Image to be Displayed into Word C#

From Dev

Convert List<string> to byte array by lines using c#

From Dev

Convert JSON to byte array in C

Related Related

  1. 1

    How to convert a .bmp image into Byte array using C Program

  2. 2

    c# How to convert pictureBox.Image to Byte Array?

  3. 3

    How to convert a byte-array to a Image in C#?

  4. 4

    c# How to convert pictureBox.Image to Byte Array?

  5. 5

    How to convert UIImagePicker image into a byte array objective-c

  6. 6

    ScalaFX: How to convert an Image object to a byte array

  7. 7

    How to convert byte array to buffered image

  8. 8

    How to convert Byte array into bitmap image?

  9. 9

    How to convert byte array to image in javascript

  10. 10

    ScalaFX: How to convert an Image object to a byte array

  11. 11

    How to convert a bitmap or byte array to an image?

  12. 12

    Convert byte array to Image

  13. 13

    Rotating a BMP image using C

  14. 14

    bind an image in c# using byte array

  15. 15

    How to convert raster byte array of an image to original image in java?

  16. 16

    convert byte array to image in Java using Google apps engine

  17. 17

    Convert PIL Image to byte array?

  18. 18

    Convert image to byte array quickly

  19. 19

    how to convert a byte[] to HttpPostedFileBase using c#

  20. 20

    How to Convert Byte Array to Image inside in Linq output List

  21. 21

    How can I convert a image into a byte array in uwp platform

  22. 22

    How to convert Bitmap image to byte array in wp7?

  23. 23

    How Can I Convert My new Byte Array To an Image

  24. 24

    how to convert BYTE array to char array for send with socket c++

  25. 25

    how to convert BYTE array to char array for send with socket c++

  26. 26

    How to create BitmapImage from a bmp file byte array?

  27. 27

    How to convert System.Byte[] into an Image to be Displayed into Word C#

  28. 28

    Convert List<string> to byte array by lines using c#

  29. 29

    Convert JSON to byte array in C

HotTag

Archive