Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- struct BMP
- {
- char Type[2]; //File type. Set to "BM".
- unsigned long Size; //Size in BYTES of the file.
- unsigned long Reserved; //Reserved. Set to zero.
- unsigned long OffSet; //Offset to the data.
- unsigned long headsize; //Size of rest of header. Set to 40.
- unsigned long Width; //Width of bitmap in pixels.
- unsigned long Height; // Height of bitmap in pixels.
- unsigned int Planes; //Number of Planes. Set to 1.
- unsigned int BitsPerPixel; //Number of Bits per pixels.
- unsigned long Compression; //Compression. Usually set to 0.
- unsigned long SizeImage; //Size in bytes of the bitmap.
- unsigned long XPixelsPreMeter; //Horizontal pixels per meter.
- unsigned long YPixelsPreMeter; //Vertical pixels per meter.
- unsigned long ColorsUsed; //Number of colors used.
- unsigned long ColorsImportant; //Number of "important" colors.
- };
- struct Pixel
- {
- unsigned char B;
- unsigned char G;
- unsigned char R;
- };
- void readBMP(char *File_Name)
- {
- BMP a;
- FILE *p = fopen(File_Name, "rb");
- if (p == NULL)
- {
- printf("Can't open file!");
- return;
- }
- else
- fread(&a, sizeof(BMP), 1, p);
- if (a.Type[0]!='B'||a.Type[1]!='M')
- {
- printf("This is not a BMP file");
- }
- else
- {
- printf("This is a BMP file\n");
- printf("The size of this file is %lu bytes\n", a.Size);
- printf("The witdth of this image is %lu pixels\n", a.Width);
- printf("The height of this image is %lu pixels\n", a.Height);
- printf("The number of bits per pixels in this image is %u\n", a.BitsPerPixel);
- }
- }
- void main()
- {
- char a[] = "test.bmp";
- readBMP(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement