C、BMP 处理...没有线索:/
我应该读取 .bmp 文件,然后根据命令行参数更改它。
示例:
-fromrow x,其中 x 指定要处理的最底行
-torow x,其中 x 指定要处理的最上面的行
-fromcol x,其中 x 指定要处理的最左边的列
-tocol x,其中 x 指定要处理的最右边的列
-op x,其中 x 是以下之一
-- 1= 图像阈值(指定范围内超过 127 的像素值更改为 255,像素值 127 或以下更改为 0)
-- 2= 负(指定范围内的任何像素值 p 更改为 255-p)
我得到了以下代码作为读取 .bmp 文件的示例:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp= fopen("sample.bmp", "r+");
if (fp == NULL){
printf("Error");
}
int temp=0;
//Go to Byte 22
fseek(fp,22,SEEK_SET);
//Read byte 22 into an integer variable
fread(&temp, sizeof(int), 1, fp);
printf("Number of Rows: %d\n", temp);
fseek(fp,18,SEEK_SET);
fread(&temp, sizeof(int), 1, fp);
printf("Number of Columns: %d\n", temp);
fseek(fp,10,SEEK_SET);
fread(&temp, sizeof(int), 1, fp);
printf("Start of Pixels: %d\n", temp);
fclose (fp);
}
什么是“像素开始”?我想我以某种方式循环遍历图像的字节并将它们复制到二维数组中......但我不知道访问文件字节的suntax?
我什至不知道从哪里开始改变图像......:/我不知所措。 任何帮助/建议/linfo/链接将不胜感激。
先感谢您。
I am supposed to read in a .bmp file and then alter it based on command line arguements.
Examples:
-fromrow x, where x specifies the bottommost row to process
-torow x, 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 t0 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)
I have been given this code as am example of reading a .bmp file:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp= fopen("sample.bmp", "r+");
if (fp == NULL){
printf("Error");
}
int temp=0;
//Go to Byte 22
fseek(fp,22,SEEK_SET);
//Read byte 22 into an integer variable
fread(&temp, sizeof(int), 1, fp);
printf("Number of Rows: %d\n", temp);
fseek(fp,18,SEEK_SET);
fread(&temp, sizeof(int), 1, fp);
printf("Number of Columns: %d\n", temp);
fseek(fp,10,SEEK_SET);
fread(&temp, sizeof(int), 1, fp);
printf("Start of Pixels: %d\n", temp);
fclose (fp);
}
What is "Start of Pixels"? I suppose I somehow loope through the bytes of the image and copy them into a 2D array...but I don't know the suntax for accessing the files bytes?
I don't even know where to start in terms of altering an image... :/ I'm at a loss.
ANY help/advice/linfo/links would be greatly appreciated.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要首先阅读
BITMAPFILEHEADER
< /a>,然后是BITMAPINFO
(其中包含BITMAPINFOHEADER
)。这些将为您提供查找和解释像素所需的信息。You'll want to start by reading in a
BITMAPFILEHEADER
, then aBITMAPINFO
(which contains aBITMAPINFOHEADER
). These will give you the information necessary to find and interpret the pixels.