資源簡介
圖像處理-讀取bmp圖像均值濾波-C++
代碼片段和文件信息
#include???
#include?“BmpRot.h“??
#include?“stdlib.h“??
#include?“math.h“??
#include???
#define?PI?3.14159//圓周率宏定義??
#define?LENGTH_NAME_BMP?30//bmp圖片文件名的最大長度??
using?namespace?std;
//變量定義??
BITMAPFILEHEADER?strHead;
RGBQUAD?strPla[256];//256色調(diào)色板??
BITMAPINFOHEADER?strInfo;
//顯示位圖文件頭信息??
void?showBmpHead(BITMAPFILEHEADER?pBmpHead)?{
cout?<“位圖文件頭:“?< cout?<“文件大小:“?< cout?<“保留字_1:“?< cout?<“保留字_2:“?< cout?<“實際位圖數(shù)據(jù)的偏移字節(jié)數(shù):“?<}
void?showBmpInforHead(tagBITMAPINFOHEADER?pBmpInforHead)?{
cout?<“位圖信息頭:“?< cout?<“結(jié)構(gòu)體的長度:“?< cout?<“位圖寬:“?< cout?<“位圖高:“?< cout?<“biPlanes平面數(shù):“?< cout?<“biBitCount采用顏色位數(shù):“?< cout?<“壓縮方式:“?< cout?<“biSizeImage實際位圖數(shù)據(jù)占用的字節(jié)數(shù):“?< cout?<“X方向分辨率:“?< cout?<“Y方向分辨率:“?< cout?<“使用的顏色數(shù):“?< cout?<“重要顏色數(shù):“?<}
int?main()?{
char?strFile[LENGTH_NAME_BMP];//bmp文件名??
IMAGEDATA?*imagedata?=?NULL;//動態(tài)分配存儲原圖片的像素信息的二維數(shù)組??
//IMAGEDATA?*imagedataRot?=?NULL;//動態(tài)分配存儲旋轉(zhuǎn)后的圖片的像素信息的二維數(shù)組??
int?width?height;//圖片的寬度和高度??
cout?<“請輸入所要讀取的文件名:“?< cin?>>?strFile;
FILE?*fpi?*fpw;
fpi?=?fopen(strFile?“rb“);
if?(fpi?!=?NULL)?{
//先讀取文件類型??
WORD?bfType;
fread(&bfType?1?sizeof(WORD)?fpi);
if?(0x4d42?!=?bfType)
{
cout?<“the?file?is?not?a?bmp?file!“?< return?NULL;
}
//讀取bmp文件的文件頭和信息頭??
fread(&strHead?1?sizeof(tagBITMAPFILEHEADER)?fpi);
showBmpHead(strHead);//顯示文件頭??
fread(&strInfo?1?sizeof(tagBITMAPINFOHEADER)?fpi);
showBmpInforHead(strInfo);//顯示文件信息頭??
//讀取調(diào)色板??
for?(unsigned?int?nCounti?=?0;?nCounti {
//存儲的時候,一般去掉保留字rgbReserved??
fread((char?*)&strPla[nCounti].rgbBlue?1?sizeof(BYTE)?fpi);
fread((char?*)&strPla[nCounti].rgbGreen?1?sizeof(BYTE)?fpi);
fread((char?*)&strPla[nCounti].rgbRed?1?sizeof(BYTE)?fpi);
cout?<“strPla[nCounti].rgbBlue“?< cout?<“strPla[nCounti].rgbGreen“?< cout?<“strPla[nCounti].rgbRed“?< }
width?=?strInfo.biWidth;
height?=?strInfo.biHeight;
imagedata?=?(IMAGEDATA*)malloc(width?*?height?*?sizeof(IMAGEDATA));
//imagedataRot?=?(IMAGEDATA*)malloc(2?*?width?*?2?*?height?*?sizeof(IMAGEDATA));
//初始化原始圖片的像素數(shù)組??
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {
(*(imagedata?+?i?*?width?+?j)).blue
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????10186??2016-12-04?00:42??back.cpp
?????文件????????9485??2016-12-19?13:23??BmpRot.cpp
?????文件????????1283??2016-12-03?19:59??BmpRot.h
?????文件??????786486??2016-12-03?19:38??lena.bmp
評論
共有 條評論