开发者

C, BMP processing...no clue :/

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, size开发者_Go百科of(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.


You'll want to start by reading in a BITMAPFILEHEADER, then a BITMAPINFO (which contains a BITMAPINFOHEADER). These will give you the information necessary to find and interpret the pixels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜