【发布时间】:2011-08-15 19:44:28
【问题描述】:
希望能为我的一项任务提供头脑风暴帮助。我要编写一个对 .bmp 图像进行基本点处理的程序。程序会打开一个.bmp文件进行读写,不会改变文件头的任何部分,而是根据命令行参数改变文件中的像素值:
-fromrow x, where x specifies the bottommost row to process
-torowx, where x specifies the topmost row to process
-fromcol x, where x specifies the leftmost column to process
-tocol x, where x specifies the rightmost column to process
-op x, where x is one of the following:
- 1 = threshold the image (any pixel value in the specifies range over 127 is changed to 255, and pixel values 127 or less is changed to 0)
- 2 = negative (any pixel value p in the specified range is changed to 255-p)
To process image data, you will need to make use of the following:
- each pixel value is an unsigned char
- the number of rows in the image is stored as an int at position (byte address) 22 in the file
- the number of columns in the image is stored as an int at position (byte address) 18 in the file
- the position at which the pixel data starts is an int stored at position (byte address) 10 in the file
- pixel information is stored row by row, starting from the bottommost row in the image (row 0) and progressing upwards. within a row; pixel information is stored left to right. padding is added to the end of each row to make row length a multiple of 4 bytes (if the row has 479 columns, there is one extra padding at the end of the row before the next row starts)
我对如何开始有点迷茫,但我想我应该先像这样制作一个结构位图?
struct bitmap {
unsigned int startrow;
unsigned int endrow;
unsigned int startcol;
unsigned int endcol;
}
谁能帮助我了解我需要为分配引用的字节地址做些什么?任何其他头脑风暴的建议也将不胜感激。谢谢!
【问题讨论】:
-
你知道如何打开文件吗?你知道如何读取文件吗?
-
那种。我的最后一项任务是从文本文件中读取和解析数据,所以我认为它会有点相似?
int main(int argc, char *argv[]) { int i; FILE *fp; for (i = 1; i < argc; i++) { fp = fopen(argv[i], "r+b"); if (fp == NULL) { fprintf(stderr, "cat: can't open %s\n", argv[i]); continue; } while (fgets(line, sizeof(line), fp) != NULL) { } fclose(fp); }不过,对于位图文件该做什么,我有点迷茫。 -
看到这个问题。您需要知道如何读取原始字节而不是文本。 stackoverflow.com/questions/5751749/…
-
不知道如何读取原始字节。你介意解释一下吗?
标签: c image-processing bitmap