c++圖像處理之24位真彩圖顏色變換的示例分析

這篇文章主要介紹了c++圖像處理之24位真彩圖顏色變換的示例分析,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

在硯山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營(yíng)銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,硯山網(wǎng)站建設(shè)費(fèi)用合理。

示例:

c++圖像處理之24位真彩圖顏色變換的示例分析

實(shí)例如下:

#include<iostream>
#include<Windows.h>
using namespace std;

bool isred(BYTE r,BYTE g,byte b){
	if(r>g&&r>b) return true;
	else return false;
}
void red2green(BYTE& r,BYTE& g,BYTE& b){
	BYTE tmp=r;
	r=g;
	g=tmp;
}

int main(){
	FILE *fpin=fopen("flo.bmp","rb+");
	if(fpin==NULL){
		cout<<"目錄里沒(méi)有輸入圖"<<endl;
		system("pause");
		return 0;
	}
	BITMAPFILEHEADER bitmapfileheader;
	BITMAPINFOHEADER bitmapinfoheader;
	fread(&bitmapfileheader,sizeof(bitmapfileheader),1,fpin);
	fread(&bitmapinfoheader,sizeof(bitmapinfoheader),1,fpin);

	if(bitmapfileheader.bfType!='B'+'M'*256){
		cout<<"不是bmp格式"<<endl;
		fclose(fpin);
		system("pause");
		return 0;
	}
	if(bitmapinfoheader.biBitCount!=24){
		cout<<"不是24位bmp"<<endl;
		fclose(fpin);
		system("pause");
		return 0;
	}


	//設(shè)置fpout
	FILE *fpout=fopen("output.bmp","wb+");

	//BITMAPFILEHEADER bitmapfileheader2;
	//BITMAPINFOHEADER bitmapinfoheader2;
	//bitmapfileheader2=bitmapfileheader;
	//bitmapinfoheader2=bitmapinfoheader;
	fwrite(&bitmapfileheader,sizeof(bitmapfileheader),1,fpout);
	fwrite(&bitmapinfoheader,sizeof(bitmapinfoheader),1,fpout);



	if(bitmapinfoheader.biClrUsed!=0){
		cout<<"是索引圖"<<endl;
		system("pause");
		return 0;
	}
	if(bitmapinfoheader.biBitCount==24){
		cout<<"24位真彩圖"<<endl;
		//int line_width=((bitmapinfoheader.biWidth*bitmapinfoheader.biBitCount+24)/32)*4;
		int line_width=bitmapinfoheader.biWidth*3;
		BYTE *line_buf=new BYTE[line_width];
		for(int i=0;i<bitmapinfoheader.biHeight;i++){
			fread(line_buf,line_width,1,fpin);			
			for(int j=0;j<bitmapinfoheader.biWidth;j++){
				BYTE b=line_buf[3*j];
				BYTE g=line_buf[3*j+1];
				BYTE r=line_buf[3*j+2];
				if(isred(r,g,b)){
					red2green(line_buf[3*j+2],line_buf[3*j+1],line_buf[3*j]);
				}
			}	
			fwrite(line_buf,line_width,1,fpout);
		}
		fclose(fpin);
		fclose(fpout);
		delete []line_buf;
		cout<<"紅變綠完成"<<endl;
	}
	
	system("pause");
	return 0;
}

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“c++圖像處理之24位真彩圖顏色變換的示例分析”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

新聞名稱:c++圖像處理之24位真彩圖顏色變換的示例分析
網(wǎng)站鏈接:http://www.muchs.cn/article32/ihehsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、域名注冊(cè)、微信公眾號(hào)營(yíng)銷型網(wǎng)站建設(shè)、企業(yè)建站、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)