資源簡介
可以將24bmp位圖 轉化成 565或者888格式的c文件。

代碼片段和文件信息
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include??
#include?“string.h“
//#include?“24.h“
//#include?“16.h“
//#include?
typedef?unsigned?long???????DWORD;
typedef?int?????????????????BOOL;
typedef?unsigned?char???????BYTE;
typedef?unsigned?short??????WORD;
typedef?float???????????????FLOAT;
typedef?unsigned?char???????byte;
//#define?MAX(abc)?a>(b>c?b:c)?a:
struct?BMP_img
{
????WORD??bfType;
????DWORD?size;
DWORD?reser;
DWORD?header_length;
????DWORD?infoheader_length;
DWORD?width;
DWORD?height;
WORD??biplanes;
WORD??bmp_type;????????/*?8bit?24bit;?*/
DWORD?compres;
DWORD?datasize;
????DWORD?bixpm;
DWORD?biypm;
DWORD?clrused;
DWORD??relclrused;
????BYTE?*image;
????byte?*header_info;
DWORD?lineBytes;
};
struct?RGB
{
byte?bitb;
byte?bitg;
byte?bitr;
byte??re;
};
void?read_img(char?*path?struct?BMP_img?*img);
void?make_src(char?*outpath?struct?BMP_img?*img);
void?display(byte?*tempint?widthint?height);
void?make_src16(char?*outpath?struct?BMP_img?*img);
void?display16(unsigned?short?*tempint?widthint?height);
#define RGB2565(x)?((((x?>>?16)?&?0xff)?>>?3)?<11)?|?((((x?>>?8)?&?0xff)?>>?2)?<5)?|?((x?&?0xff)?>>?3)
#define?RGB2_565(rgb)??(unsigned?short)((((unsigned)(r)?<8)?&?0xF800)|(((unsigned)(g)?<3)?&?0x7E0)|(((unsigned)(b)?>>?3)))
#define?RGB565_2(x)?(unsigned?int)(((unsigned?int)(x&0x1f))|((unsigned?int)((x&0x7e0)<<5))|((unsigned?int)((x&0xF800)<<8)))
#define?RGB565_24(rgbrgb) do{r=(unsigned)(rgb>>8)&0xff;g=(unsigned)(rgb>>3)&0xff;b=(unsigned)(rgb<<3)&0xff;}while(0)
#define?bigrvs(x)?(unsigned?int)((x&0xff)<<16)|((unsigned?int)(x&0x00ff00))|((unsigned?int)(x&0xff0000)>>16)
int?main()
{
// int?ijnflag;
// unsigned?char?*temp=(unsigned?char?*)bsp_img;
// unsigned?short?*temp1=(unsigned?short?*)bsp_img16;
struct?BMP_img?img;
// initgraph(480480);
// read_img(“2.bmp“?&img);
// make_src(“24.h“&img);
// make_src16(“16.h“&img);
// display(temp480272);
// display16(temp1480272);
int?flag;
char?srcbmp[100]={0};
char?dstfile[100]={0};
printf(“Please?input?24bit?bmp?path?name\nC?file?path?name\n16?or?24bit\n“);
scanf(“%s?%s?%d“srcbmpdstfile&flag);
read_img(srcbmp?&img);
if(flag==16)
make_src16(dstfile&img);
if(flag==24)
make_src(dstfile&img);
printf(“\nConvert?Over\nPlease?Check\n“);
return?0;
}
void?read_img(char?*path?struct?BMP_img?*img)
{
FILE?*infile;
DWORD?ijlbitcolor;
DWORD?line24;
DWORD?line8;
????struct?RGB?*bitmap;
if((infile=fopen(path“rb“))==NULL)
{
printf(?“\nCan?not?open?the?path:?%s?\n“?path);
exit(-1);
}
fread(&img->bfTypesizeof(WORD)1infile);//printf(“\n打開的圖為?%d“img->bfType);
fread(&img->sizesizeof(DWORD)1infile);??????????printf(“\n圖片大小為:%d“img->size);
fread(&img->resersizeof(DWORD)1infile);//printf(“\n保留位:“);
fread(&img->header_lengthsizeof
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????391734??2012-05-06?16:34??bmp24_to_565_or_24_Cfile\2.bmp
?????文件??????40960??2008-06-21?11:57??bmp24_to_565_or_24_Cfile\Bmp2C.exe
?????文件???????1232??2012-05-06?20:43??bmp24_to_565_or_24_Cfile\ReadMe.txt
?????文件???????9137??2012-05-18?22:22??bmp24_to_565_or_24_Cfile\rgb565test.cpp
?????文件???????4618??2012-05-06?23:49??bmp24_to_565_or_24_Cfile\rgb565test.dsp
?????文件????????528??2012-05-06?20:43??bmp24_to_565_or_24_Cfile\rgb565test.dsw
?????文件??????66560??2012-05-18?22:26??bmp24_to_565_or_24_Cfile\rgb565test.ncb
?????文件??????55808??2012-05-18?22:26??bmp24_to_565_or_24_Cfile\rgb565test.opt
?????文件???????3634??2012-05-18?22:25??bmp24_to_565_or_24_Cfile\rgb565test.plg
?????文件????????297??2012-05-06?20:43??bmp24_to_565_or_24_Cfile\StdAfx.cpp
?????文件????????769??2012-05-06?20:43??bmp24_to_565_or_24_Cfile\StdAfx.h
?????目錄??????????0??2012-05-18?22:26??bmp24_to_565_or_24_Cfile
-----------?---------??----------?-----??----
???????????????575277????????????????????12
- 上一篇:指定地區代理IP獲取并多線程校驗項目完整
- 下一篇:旅行商問題的數學規劃模型
評論
共有 條評論