資源簡介
C語言實現圖像的旋轉縮放裁切,此為本人圖像處理與成像制導的作業,完全可以實現,并且附有詳細的實驗報告。旋轉可以自己輸入旋轉的角度,切割可以輸入切割的大小,縮放也是任意比例的縮放,可以自己輸入比例系數。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?“stdafx.h“
#define??pi??3.1415
float????zoomnumber=1;????//初始放大倍數默認為1
unsigned?char?*pBmpBuf;???//讀入圖像數據的指針
unsigned?char?*pNewBmpBuf;
int????????bmpWidth;??????//圖像的寬
int????????bmpHeight;?????//圖像的高
RGBQUAD????*pColorTable;??//顏色表指針
int????????biBitCount;????//圖像類型,每像素位數
int???????newBmpWidth;???//變化后圖像的寬
int???????newBmpHeight;??//變化后圖像的高
int???????newLineByte;???//變化后圖像數據每行的字節數
unsigned?char?*?rotate(unsigned?char?*pImage?int?width?int?height?int?biBitCount?float?angle);
void?crop(long?Widthunsigned?char?*pImagelong?x1long?x2long?y1long?y2);
void?ShowImage(char?*?bmpName);
int?ReadBmp(const?char*?bmpName)
{FILE?*fp=fopen(bmpName“rb“);
if(fp==0)
??{??printf(“打開文件失敗\n“);
???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);
return?1;
}
/****************************************************************************
*函數名稱:?saveBmp()
*函數參數:?const?char?*bmpName????寫入bmp格式文件的名稱及路徑
????unsigned?char?*imgBuf?待存盤的位圖數據
????int?width?????????????以像素為單位待存盤的位圖寬
????int?height????????????以像素為單位待存盤的位圖高
????int?biBitCount????????每個像素占的位數
????RGBQUAD?*pColorTable???顏色表指針
*函數返回值:0為失敗?1為成功
*函數描述:給定寫入bmp文件的名稱和路徑,寫入圖像的位圖數據,寬,高,寫進文件中
***************************************************************************/
int?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;
}
void?PrintMenu()
{printf(“?------選擇您的操作------\n“);
printf
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-11-29?11:20??C語言實現圖像的旋轉縮放裁切\
?????目錄???????????0??2012-11-29?11:20??C語言實現圖像的旋轉縮放裁切\bmp\
?????文件??????263222??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\bmp\dollar.bmp
?????文件???????65262??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\bmp\dollarcut.bmp
?????文件??????553126??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\bmp\large.bmp
?????文件??????361078??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\bmp\rotate79.bmp
?????文件???????17206??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\bmp\small.bmp
?????文件???????10853??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\main.cpp
?????文件?????????233??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\stdafx.h
?????文件?????????498??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\targetver.h
?????文件??????705703??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\Wssillustrate.pdf
?????文件?????????891??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\wsswork2.sln
?????文件????????3918??2012-11-24?09:50??C語言實現圖像的旋轉縮放裁切\wsswork2.vcxproj
- 上一篇:用C語言編寫的經典小游戲
- 下一篇:php-5.3.5-Win32-VC6-x64
評論
共有 條評論