資源簡介
bmp格式圖片縮小,驗證可用,vc2010下,不過并不清晰,要求更好的壓縮,不建議用這個
代碼片段和文件信息
#include?
#include?
#define?FXZOOMRATIO?0.5//x軸縮放倍數
#define?FYZOOMRATIO?0.5//y軸縮放倍數
unsigned?char*?pBmpBuf;//讀入圖像數據的指針
unsigned?char*?pNewBmpBuf;
int?bmpWidth;//圖像的寬
int?bmpHeight;//圖像的高
RGBQUAD*?pColorTable;//顏色表指針
int?biBitCount;//圖像類型,每像素位數
long?newBmpWidth;//變化后圖像的寬
long?newBmpHeight;//變化后圖像的高
long?newLineByte;//變化后圖像數據每行的字節數
/****************************************************************************
*函數名稱:readBmp()
*函數參數:const?char?*bmpName?讀入bmp格式文件的名稱及路徑
*函數返回值:0為失敗?1為成功
*函數描述:給定文件的名稱和路徑?讀入圖像的位圖數據,寬,高,及每個像素的位數進內存,保存在全局變量中
***************************************************************************/
bool?readBmp(const?char*?bmpName)
{
FILE*?fp=fopen(bmpName“rb“);
if(fp==0)
{
printf(“cannot?open?file“);
return?0;
}
fseek(fpsizeof(BITMAPFILEHEADER)0);
BITMAPINFOHEADER?head;
fread(&headsizeof(BITMAPINFOHEADER)1fp);
bmpWidth?=?head.biWidth;
bmpHeight?=?head.biHeight;
biBitCount?=?head.biBitCount;
int?lineByte?=?(bmpWidth?*biBitCount/8+3)/4*4;//計算圖像每行像素所占的字節數
if(biBitCount?==?8)
{
pColorTable?=?new?RGBQUAD[256];
fread(pColorTablesizeof(RGBQUAD)256fp);
}
pBmpBuf?=?new?unsigned?char?[lineByte*?bmpHeight];
fread(pBmpBuf1lineByte*bmpHeightfp);
fclose(fp);
return?1;
}
/****************************************************************************
*函數名稱:?saveBmp()
*函數參數:?const?char?*bmpName????寫入bmp格式文件的名稱及路徑
????unsigned?char?*imgBuf?待存盤的位圖數據
????int?width?????????????以像素為單位待存盤的位圖寬
????int?height????????????以像素為單位待存盤的位圖高
????int?biBitCount????????每個像素占的位數
????RGBQUAD?*pColorTable???顏色表指針
*函數返回值:0為失敗?1為成功
*函數描述:給定寫入bmp文件的名稱和路徑?要寫入圖像的位圖數據,寬,高,寫進文件中
***************************************************************************/
bool?saveBmp(const?char*?bmpNameunsigned?char*?imgBufint?widthint?heightint?biBitCountRGBQUAD*?pColorTable)
{
if(!imgBuf)//imgBuf?待存盤的位圖數據
return?0;
int?colorTablesize?=?0;
if(biBitCount?==?8)
colorTablesize?=1024;
int?lineByte?=?(width?*?biBitCount/8+3)/4*4;
FILE?*fp?=?fopen(bmpName“wb“);
if(fp?==?0)
return?0;
BITMAPFILEHEADER?fileHead;
fileHead.bfType=?0x4d42;
fileHead.bfSize?=?sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)?+?colorTablesize?+?lineByte?*height;
fileHead.bfReserved1?=?0;
fileHead.bfReserved2?=?0;
fileHead.bfOffBits?=?54?+colorTablesize;
fwrite(&fileHeadsizeof(BITMAPFILEHEADER)1fp);
BITMAPINFOHEADER?head;
head.biBitCount?=?biBitCount;
head.biClrImportant?=?0;
head.biClrUsed?=?0;
head.biCompression?=?0;
head.biHeight?=?height;
head.biPlanes?=1;
head.biSize?=?40;
head.biSizeImage?=?lineByte?*height;
head.biWidth?=?width;
head.biXPelsPerMeter?=?0;
head.biYPelsPerMeter?=?0;
fwrite(&headsizeof(BITMAPINFOHEADER)1fp);
if(biBitCount?==?8)
fwrite(pColorTablesizeof(RGBQUAD)256fp);
fwrite(imgBufheight?*?lineByte1fp);
fclose(fp);
return?1;
}
/****************************************************************************
*函
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-08-27?14:37??Debug\
?????文件???????31744??2015-08-26?16:53??Debug\bmp_narrow.exe
?????文件??????328732??2015-08-26?16:53??Debug\bmp_narrow.ilk
?????文件??????445440??2015-08-26?16:53??Debug\bmp_narrow.pdb
?????目錄???????????0??2015-08-27?14:38??bmp_narrow\
?????目錄???????????0??2015-08-27?14:37??bmp_narrow\Debug\
?????文件???????12796??2015-08-26?16:53??bmp_narrow\Debug\CL.read.1.tlog
?????文件?????????264??2015-08-26?16:53??bmp_narrow\Debug\CL.write.1.tlog
?????文件?????????406??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.exe.em
?????文件?????????472??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.exe.em
?????文件?????????381??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.exe.intermediate.manifest
?????文件??????????41??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.lastbuildstate
?????文件????????3595??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.log
?????文件???????31014??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow.obj
?????文件?????????210??2015-08-26?16:53??bmp_narrow\Debug\bmp_narrow_manifest.rc
?????文件?????????610??2015-08-26?16:53??bmp_narrow\Debug\cl.command.1.tlog
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件???????????2??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件????????1356??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件????????2852??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件?????????582??2015-08-26?16:53??bmp_narrow\Debug\li
?????文件?????????370??2015-08-26?16:53??bmp_narrow\Debug\mt.command.1.tlog
?????文件?????????266??2015-08-26?16:53??bmp_narrow\Debug\mt.read.1.tlog
?????文件?????????266??2015-08-26?16:53??bmp_narrow\Debug\mt.write.1.tlog
?????文件?????????494??2015-08-26?16:53??bmp_narrow\Debug\rc.command.1.tlog
?????文件?????????238??2015-08-26?16:53??bmp_narrow\Debug\rc.read.1.tlog
?????文件?????????246??2015-08-26?16:53??bmp_narrow\Debug\rc.write.1.tlog
............此處省略13個文件信息
評論
共有 條評論