资源简介
本代码实现了24位BMP图片转565格式16位数组C文件,用法: 24to16 filename.bmp 生成:16filename.bmp 生成的16filename.bmp只能用附件中的“画图”打开!
代码片段和文件信息
// 24to16.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include
#include
#define DATA 0x46
int ch24_16(char crchar cg char cb);
void cursor(char *filename int x int y int w int h);
unsigned char head[]={
0x420x4d0x460x000x180x000x000x000x000x000x460x000x000x000x380x00
0x000x000x000x040x000x000x000x030x000x000x010x000x100x000x030x00
0x000x000x000x000x180x000xc40x0e0x000x000xc40x0e0x000x000x000x00
0x000x000x000x000x000x000x000xf80x000x000xe00x070x000x000x1f0x00
0x000x000x000x000x000x00};
unsigned long *FileSize = (unsigned long *) (head + 2);
unsigned long *Width = (unsigned long *) (head + 0x12);
unsigned long *Height = (unsigned long *) (head + 0x16);
int main(int argc char* argv[])
{
unsigned long i datalen;
FILE *fp1 *fp2;
char file2[15] = “16“;
unsigned char crcgcb;
int data24 color16;
if(argc < 2){printf(“Useage:24to16 file1.bmp\n“); exit(1);}
fp1 = fopen(argv[1] “rb“) ;
strcat(file2argv[1]);
fp2 = fopen(file2 “wb“);
fseek(fp1 0x0a 0);
data24 = fgetc(fp1);
fseek(fp1 0x12 0);
fread((void*)Width41fp1);
fread((void*)Height41fp1);
datalen = *Width * *Height;
*FileSize = datalen * 2 + DATA;
for(i = 0; i < DATA; i++)
fputc(head[i]fp2);
fseek(fp1 data24 0);
while(!feof(fp1))
{
cr=fgetc(fp1);
cg=fgetc(fp1);
cb=fgetc(fp1);
color16 = ch24_16(crcgcb);
fwrite((void*)&color1621fp2);
}
fclose(fp1) ;
fclose(fp2) ;
cursor(file21001003015);
return 0;
}
int ch24_16(char crchar cg char cb)
{
int re;
re = ((((int)cb)<<8)&0xf800)|((((int)cg)<<3)&0x07e0)|((((int)cr)>>3)&0x001f);
return re;
}
void cursor(char * filename int x int y int w int h){
char filebuf[1024];
FILE *fp1 *fp2;
int width;
if(w * h * 2 > 1024){printf(“%d * %d Area is to big!“wh);return;}
fp1 = fopen(filename “rb“) ;
fseek(fp1 0x12 0);
fread((void*)Width41fp1);
width = (int)(*Width);
fread((void*)Height41fp1);
for(int i = 0; i < h; i++){
fseek(fp1 DATA + ((y + i) * (width) + x)* 2 0); //Width replace by xres
fread((void *)(filebuf + w * i *2) w * 2 1 fp1);
}
for(i = 0; i < 1024; i++)filebuf[i] = ~filebuf[i];
rewind(fp1) ;
fp2 = fopen(“try.bmp“ “wb“) ;
while(!feof(fp1))
{
fputc(fgetc(fp1)fp2);
}
rewind(fp2);
for(i = 0; i < h; i++){
fseek(fp2 DATA + ((y + i) * (width) + x)* 2 0); //Width replace by xres
fwrite((void *)(filebuf + w * i *2) w * 2 1 fp2);
}
fclose(fp1) ;
fclose(fp2);
return;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2753 2012-12-12 11:18 24to16\24to16.cpp
文件 4536 2012-11-20 20:06 24to16\24to16.dsp
文件 518 2012-11-20 20:11 24to16\24to16.dsw
文件 50176 2012-12-12 11:20 24to16\24to16.ncb
文件 48640 2012-12-12 11:20 24to16\24to16.opt
文件 1671 2012-12-12 11:19 24to16\24to16.plg
文件 184371 2012-12-12 11:19 24to16\Debug\24to16.exe
文件 190004 2012-12-12 11:19 24to16\Debug\24to16.ilk
文件 6703 2012-12-12 11:19 24to16\Debug\24to16.obj
文件 203728 2012-12-12 11:19 24to16\Debug\24to16.pch
文件 377856 2012-12-12 11:19 24to16\Debug\24to16.pdb
文件 1832 2012-12-12 11:19 24to16\Debug\StdAfx.obj
文件 41984 2012-12-12 11:19 24to16\Debug\vc60.idb
文件 53248 2012-12-12 11:19 24to16\Debug\vc60.pdb
文件 1208 2012-11-20 20:06 24to16\ReadMe.txt
文件 293 2012-11-20 20:06 24to16\StdAfx.cpp
文件 769 2012-11-20 20:06 24to16\StdAfx.h
目录 0 2012-12-12 11:19 24to16\Debug
目录 0 2012-12-12 11:20 24to16
----------- --------- ---------- ----- ----
1170290 19
评论
共有 条评论