天天看點

數字圖像處理_真彩圖轉換灰階圖_純C

頭檔案見軟體開發其他關于數字圖像進行中loadbmp.h

nocolor.c

#include "loadbmp.h"

void NoColor()
{
	int x,y,p;
	BYTE Point;
	if (lpBitmap==0) return;

	for(y=0;y<nHeight;y++)
		for(x=0;x<nWidth;x++)
		{
			p=x*3+y*nByteWidth;
			Point=(BYTE)(0.299*(float)lpBits[p+2]+0.587*(float)lpBits[p+1]+0.114*(float)lpBits[p]+0.1);
			lpBits[p+2]=Point;
			lpBits[p+1]=Point;
			lpBits[p]=Point;
		}
}

void main(int argc, char *argv[])
{
	OpenFile();
	NoColor();
	SaveAs();
}
           

轉換前:

數字圖像處理_真彩圖轉換灰階圖_純C

轉換後:

數字圖像處理_真彩圖轉換灰階圖_純C