[問題]c++builder 問題 |
尚未結案
|
max49110018
一般會員 發表:3 回覆:0 積分:0 註冊:2005-03-15 發送簡訊給我 |
1.show a diloague box to choice a BMP files.
2. load the choiced BMP files (baybe colorful) to a image.
3. convert the pixels in image to grey level according to the foregoing formula and save to a dynamic array.
4. convert the colorful image to a gray one. 發表人 - taishyang 於 2005/03/15 22:28:38
|
fnk
高階會員 發表:40 回覆:149 積分:102 註冊:2004-01-02 發送簡訊給我 |
void __fastcall TForm1::Button1Click(TObject *Sender) { // 動態產生一個影像 if(OpenPictureDialog1->Execute()) { if(FileExists(OpenPictureDialog1->FileName)) { if (Image1) delete Image1; Image1 = new TImage(Form1); Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); Image1->Align = alClient; Image1->Stretch = false; Image1->Visible = true; Image1->Parent = Form1; } } } void __fastcall TForm1::Button2Click(TObject *Sender) { int i,j,Row,Col; Graphics::TBitmap *pic = Image1->Picture->Bitmap; if(!pic->Empty) { // 動態宣告一個Buffer, 用來存計算出來的灰階值結果 unsigned char **Buffer = new unsigned char*[pic->Height]; for (i=0; i< pic->Height; i ) Buffer[i] = new unsigned char[pic->Width]; // 將原影像的R,G,B 按照公式..轉成灰階值..放到Buffer中 pic->PixelFormat = pf32bit; RGBQUAD *Pixel; for (Row=0; Row < pic->Height ; Row ) { Pixel = (RGBQUAD *) pic->ScanLine[Row]; for (Col=0; Col < pic->Width; Col , Pixel ) Buffer[Row][Col] = (BYTE) ((float)Pixel->rgbRed*0.299 (float)Pixel->rgbGreen*0.587 (float)Pixel->rgbBlue*0.114); } // 將結果蓋過原來的影像 for (Row=0; Row < pic->Height ; Row ) { Pixel = (RGBQUAD *) pic->ScanLine[Row]; for (Col=0; Col < pic->Width; Col , Pixel ) { Pixel->rgbRed = (BYTE) Buffer[Row][Col]; Pixel->rgbGreen = (BYTE) Buffer[Row][Col]; Pixel->rgbBlue = (BYTE) Buffer[Row][Col]; } } Image1->Invalidate(); // 刪除動態宣告的Buffer for (i=0; iHeight; i ) delete[] Buffer[i]; delete [] Buffer; } }=========== 有興趣,就能進步 =========== |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |