#include <stdio.h>
#include <stdlib.h>
#define COLS 192
#define ROWS 145
int main()
{
FILE *image_input;
FILE *image_output;
int i, j, k;
int m=0;
unsigned int OutputImage[ROWS][COLS][3];
unsigned char header[54] = {
0x42,
0x4d,
0, 0, 0, 0,
0, 0,
0, 0,
54, 0, 0, 0,
40, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 0,
24, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
const int row = ROWS;
const int col = COLS;
int x;
if ((image_input = fopen("clena.bmp","rb")) == NULL)
{
printf( "Can't open file");
}
else
{
for(i=0;i<54;i++)
header[i] = fgetc(image_input);
image_output = fopen("clena.txt","wb");
for(i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
fprintf(image_output, "0x");
for (k=0; k<3; k++)
{
OutputImage[i][j][k] = fgetc(image_input);
fprintf(image_output, "%x", OutputImage[i][j][k]);
//fprintf(image_output, "0x%x,", OutputImage[i][j][k]);
}
fprintf(image_output, ",");
if (j%6==1)
fprintf(image_output, "\n ");
}
}
fclose(image_input);
fclose(image_output);
}
}
結果:
0x1b1b2b,0x151321,
0x12f1b,0x12f17,0x12f16,0x12e17,0x12d1a,0x12d18,
0x12101e,0x243049,0x496488,0x6f85ab,0x8d95bb,0xa0a3c8,
0xaaacd0,0xb2b3d5,0xbbbadb,0xc4c1e0,0xc9c3e2,0xcec6e3,
0xd4cae4,0xd8cce5,0xdacde5,0xd9cce4,0xd2c9e1,0xcec6e1,
...
--------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define COLS 64
#define ROWS 64
int main()
{
FILE *image_input;
FILE *image_output;
int i, j, k;
int m=0;
unsigned int OutputImage[ROWS][COLS][3];
unsigned int one;
unsigned char header[54] = {
0x42,
0x4d,
0, 0, 0, 0,
0, 0,
0, 0,
54, 0, 0, 0,
40, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 0,
24, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
const int row = ROWS;
const int col = COLS;
int x;
if ((image_input = fopen("clena.bmp","rb")) == NULL)
{
printf( "Can't open file");
}
else
{
for(i=0;i<54;i++)
header[i] = fgetc(image_input);
image_output = fopen("clena.txt","wb");
for(i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
for (k=0; k<3; k++)
{
fprintf(image_output, "0x");
OutputImage[i][j][k] = fgetc(image_input);
one=OutputImage[i][j][k];
fprintf(image_output, "%x", one);
fprintf(image_output, ", ");
}
if (j%2==0)
fprintf(image_output, "\n");
}
}
fclose(image_input);
fclose(image_output);
}
}
結果:
0x1b,0x1b,0x2b,0x15,0x13,0x21,
0xaa,0x1b,0x3c,0x1c
...
ref:
1. 酷!學園
2. 真OO無雙之真亂舞
3. 靖。技場
沒有留言:
張貼留言