无法完美读取bmp文件

时间:2014-06-10 05:39:34

标签: c visual-studio image-processing bmp

我是C的新手,我写了一个c代码,用于简单地读取具有32位深度的2448x280像素的bmp文件并将其写入新的bmp文件。为此,我逐个读取像素。我正在完美地阅读标题,但问题是在对像素完成读写操作之后,当前位置原始图像是= 2741814,这对我来说是正确的但结果图像的位置= 2903490。所以,请告诉我在哪里是错误的。 这是我的代码: -

#include<stdio.h>
#include<conio.h>


void main(void)
{
    long int length;
    int count,r,c,p;
    FILE *image;
    FILE *result;
    char read_pixels;
    image=fopen("image.bmp","rb");
    result=fopen("result.bmp","w+");

    for(count=0;count<54;count++)
    {

    fread(&read_pixels,1,sizeof(read_pixels),image);
    fprintf(result,"%c",read_pixels);
    }

    for(c=0;c<280;c++)
    {
        for(r=0;r<2448;r++)
        {
            for(p=0;p<4;p++)
            {
                fread(&read_pixels,1,sizeof(read_pixels),image);
                fprintf(result,"%c",read_pixels);
            }
        }
    }

    fseek(image,0,SEEK_CUR);
    length=ftell(image);
    printf("position of image after reading pixels =%d\n",length);
    fseek(result,0,SEEK_CUR);
    length=ftell(result);
    printf("position of result after writing pixels=%d\n",length);
    fclose(image);
    fclose(result);
    getch();
}

0 个答案:

没有答案
相关问题