#include<stdlib.h> #include<stdio.h> #include<string.h>

#define height 256 #define width 256

int main() { unsigned char srcimg[height][width]; FILE* fpin; int i,j;

fpin = fopen('barbara512.raw', 'rb');
if(fpin == NULL) {
    printf('Failed to open input file.

'); return 1; }

for(i=0; i<height; i++) {
    for(j=0; j<width; j++) {
        fread(&srcimg[i][j], 1, 1, fpin);
        printf('%d ',(int)srcimg[i][j]);
    }
    printf('

'); }

fclose(fpin);

FILE* fpout;
fpout = fopen('D:/lena256.doc', 'w+');
if(fpout == NULL) {
    printf('Failed to open output file.

'); return 1; }

for(i=0; i<height; i++) {
    for(j=0; j<width; j++) {
        fprintf(fpout, '%d ', (int)srcimg[i][j]); 
    }
    fprintf(fpout, '

'); }

fclose(fpout);

fpout = fopen('D:/lena256_prc.raw', 'wb');
if(fpout == NULL) {
    printf('Failed to open output file.

'); return 1; }

for(i=0; i<height; i++) {
    for(j=0; j<width; j++) {
        fwrite(&srcimg[i][j], 1, 1, fpout); 
    }
}

fclose(fpout);

return 0;

}

C语言代码优化:处理图像数据并写入文件

原文地址: https://www.cveoy.top/t/topic/ptdi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录