首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >image.bmp上的.bmp图像比较显示EOF

image.bmp上的.bmp图像比较显示EOF
EN

Stack Overflow用户
提问于 2016-12-23 18:18:05
回答 1查看 487关注 0票数 0

我需要与.bmp类型的图像工作。它的格式是:

代码语言:javascript
复制
struct bmp_fileheader
{
    unsigned char  fileMarker1; /* 'B' */
    unsigned char  fileMarker2; /* 'M' */
    unsigned int   bfSize; /* File's size */
    unsigned short unused1; /* Aplication specific */
    unsigned short unused2; /* Aplication specific */
    unsigned int   imageDataOffset; /* Offset to the start of image data */
};

struct bmp_infoheader
{
    unsigned int   biSize; /* Size of the info header - 40 bytes */
    signed int     width; /* Width of the image */
    signed int     height; /* Height of the image */
    unsigned short planes;
    unsigned short bitPix; /* Number of bits per pixel = 3 * 8 (for each channel R, G, B we need 8 bits */
    unsigned int   biCompression; /* Type of compression */
    unsigned int   biSizeImage; /* Size of the image data */
    int            biXPelsPerMeter;
    int            biYPelsPerMeter;
    unsigned int   biClrUsed;
    unsigned int   biClrImportant;
};

typedef struct pi {
  unsigned char r;
  unsigned char g;
  unsigned char b;
}Pixel;

struct bmp_image {
  struct bmp_fileheader file_header;
  struct bmp_infoheader info_header;
  Pixel ** pixel;
};

struct bmp_image image;

因此,一个图像包含一个头和一个像素矩阵(height * width)。我从一个文件中读取了图像:

代码语言:javascript
复制
FILE *image_file = fopen("path.bmp", "rb");

在那之后,我读取头的所有变量,然后是像素矩阵。我需要对图像进行一些更改,以便从初始图像创建另一个black_and_white格式的图像。执行此操作的算法是使用(B,B,B)更改(X,Y,Z)像素,其中B = (X + Y + Z) / 3;。我可以很好地创建black_and_white镜像。当我尝试将我的black_and_white图像与由paint程序生成的black_and_white图像进行比较时,出现了问题。

代码语言:javascript
复制
cmp -lb airplane_black_white.bmp ref/airplane_black_white.bmp 
cmp: EOF on airplane_black_white.bmp
EN

回答 1

Stack Overflow用户

发布于 2016-12-23 18:29:45

我经常看到人们一个接一个地想着像素的整齐布局。事实并非如此。它们在扫描线上一个接一个地布局,然后一条又一条扫描线,扫描线可以包含几个未使用的字节,以便在字边界上对齐它。但你会说:

因此,图像包含一个头和一个像素矩阵(height * width)。

但事实并非如此。您必须处理扫描线,而图片由由像素组成的扫描线组成。这通常比你的heigth * width更高,这解释了为什么比较过早地看到了EOF。

有关如何处理位图图像,请参阅What is wrong with this code for writing grey-scale bmp from an image RGB bmp pure C - Windows OS

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41299477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档