請教一下TIamge的問題?? |
尚未結案
|
snake720105
一般會員 發表:7 回覆:12 積分:3 註冊:2005-02-16 發送簡訊給我 |
|
wu-eric
中階會員 發表:14 回覆:82 積分:64 註冊:2004-03-17 發送簡訊給我 |
這個給你參考
我之前就是用這個做出來的
http://delphi.ktop.com.tw/topic.php?topic_id=36518
|
wu-eric
中階會員 發表:14 回覆:82 積分:64 註冊:2004-03-17 發送簡訊給我 |
下面這段程式你再試試看是不是你要的
需用PaintBox 和 Image兩個物件範圍大小一致且重疊,及Image設Enable=false
bool gbMDown; TRect grtLTRB; void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbMDown=true; grtLTRB.Left=X; grtLTRB.Top=Y; grtLTRB.Right=X; grtLTRB.Bottom=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int i; TRect cmp; if(gbMDown) { if(X<0) X=0; if(X>PaintBox1->Width) X=PaintBox1->Width; if(Y<0) Y=0; if(Y>PaintBox1->Height) Y=PaintBox1->Height; PaintBox1->Canvas->CopyMode=cmSrcCopy; PaintBox1->Canvas->CopyRect(grtLTRB, Image1->Canvas, grtLTRB); grtLTRB.Right=X; grtLTRB.Bottom=Y; cmp=grtLTRB; if(cmp.Bottom發表人 - Wu-Eric 於 2005/04/19 19:55:40 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
snake720105
一般會員 發表:7 回覆:12 積分:3 註冊:2005-02-16 發送簡訊給我 |
引言: 下面這段程式你再試試看是不是你要的 需用PaintBox 和 Image兩個物件範圍大小一致且重疊,及Image設Enable=false可否說明一下PaintBox在這裡面所扮演的腳色,還未使用過PaintBox這個元件 以下是我的程式碼,但是卻無法清除上一次所畫的,請指教,大大上面所提供的程式碼我之前有下載過類似的範例IMAGERECT,但是卻不知PaintBox與IMAGE成何種關係bool gbMDown; TRect grtLTRB; void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbMDown=true; grtLTRB.Left=X; grtLTRB.Top=Y; grtLTRB.Right=X; grtLTRB.Bottom=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int i; TRect cmp; if(gbMDown) { if(X<0) X=0; if(X>PaintBox1->Width) X=PaintBox1->Width; if(Y<0) Y=0; if(Y>PaintBox1->Height) Y=PaintBox1->Height; PaintBox1->Canvas->CopyMode=cmSrcCopy; PaintBox1->Canvas->CopyRect(grtLTRB, Image1->Canvas, grtLTRB); grtLTRB.Right=X; grtLTRB.Bottom=Y; cmp=grtLTRB; if(cmp.Bottom發表人 - Wu-Eric 於 2005/04/19 19:55:40 void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { F_X=X; F_Y=Y; if(Drawing==true) { Image1->Canvas->Pen->Color=clRed; Image1->Canvas->LineTo(F_X,S_Y); Image1->Canvas->LineTo(F_X,F_Y); Image1->Canvas->LineTo(S_X,F_Y); Image1->Canvas->LineTo(S_X,S_Y); Image1->Canvas->Brush->Style=bsClear; } } void __fastcall TForm1::Image1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Drawing=true; //如按下滑鼠,就開啟虛線繪出功能 S_X=X; S_Y=Y; Image1->Canvas->MoveTo(S_X,S_Y); void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Drawing=False; Image1->Canvas->Pen->Color=clRed; Image1->Canvas->LineTo(F_X,S_Y); Image1->Canvas->LineTo(F_X,F_Y); Image1->Canvas->LineTo(S_X,F_Y); Image1->Canvas->LineTo(S_X,S_Y); //繪出手動圈選範圍 X1Edit->Text=S_X; Y1Edit->Text=S_Y; X2Edit->Text=F_X; Y2Edit->Text=F_Y;輕步玉階飛夜色~~ 不勝蕭然掩月來~~ 發表人 - snake720105 於 2005/04/20 09:10:39
------
輕步玉階飛夜色~~ 不勝蕭然掩月來~~ |
snake720105
一般會員 發表:7 回覆:12 積分:3 註冊:2005-02-16 發送簡訊給我 |
我已經可以針對圖面進行框選了,不過有個缺點是框選的時候refresh的速度,會造成殘影,是否有更好的方法可以提供,我看過IMAGERECT這個範例它框選的時候不會有殘影,但是我希望用自己的方法寫,以下是我的程式碼,請指教
void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { S_X=X; S_Y=Y; Drawing=true; grtLTRB.Left=X; grtLTRB.Top=Y; grtLTRB.Right=X; grtLTRB.Bottom=Y; PaintBox1->Canvas->MoveTo(S_X,S_Y); void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { F_X=X; F_Y=Y; int R=GetRValue(Image1->Canvas->Pixels[X][Y]); int G=GetGValue(Image1->Canvas->Pixels[X][Y]); int B=GetBValue(Image1->Canvas->Pixels[X][Y]); int Gray = 0.299*R 0.587*G 0.114*B; StatusBar1->Panels->Items[0]->Text = "R:" IntToStr(R); StatusBar1->Panels->Items[1]->Text = "G:" IntToStr(G); StatusBar1->Panels->Items[2]->Text = "B:" IntToStr(B); StatusBar1->Panels->Items[3]->Text = "X:" IntToStr(X); StatusBar1->Panels->Items[4]->Text = "Y:" IntToStr(Y); StatusBar1->Panels->Items[5]->Text = "Gray:" IntToStr(Gray); if(Drawing==true) { Refresh(); if(X<0) X=0; if(X>479) X=479; if(Y<0) Y=0; if(Y>511) Y=511; grtLTRB.Right=X; grtLTRB.Bottom=Y; PaintBox1->Canvas->Pen->Style=psDot; PaintBox1->Canvas->Pen->Color=clRed; PaintBox1->Canvas->LineTo(F_X,S_Y); PaintBox1->Canvas->LineTo(F_X,F_Y); PaintBox1->Canvas->LineTo(S_X,F_Y); PaintBox1->Canvas->LineTo(S_X,S_Y); } Drawing=False; PaintBox1->Canvas->Pen->Color=clRed; PaintBox1->Canvas->LineTo(F_X,S_Y); PaintBox1->Canvas->LineTo(F_X,F_Y); PaintBox1->Canvas->LineTo(S_X,F_Y); PaintBox1->Canvas->LineTo(S_X,S_Y); //繪出手動圈選範圍 X1Edit->Text=S_X; Y1Edit->Text=S_Y; X2Edit->Text=F_X; Y2Edit->Text=F_Y;輕步玉階飛夜色~~ 不勝蕭然掩月來~~ 發表人 - snake720105 於 2005/04/22 17:33:32
------
輕步玉階飛夜色~~ 不勝蕭然掩月來~~ |
stellos
中階會員 發表:24 回覆:84 積分:51 註冊:2004-06-08 發送簡訊給我 |
int Box_x,Box_y; //全域變數 OnMouseDown紀錄框起點 Box_x=X; Box_y=Y; OnMouseMove
{
TRect si;
//if(MsDown==1)
//{
si.Top=0;
si.Left=0;
si.Bottom=Image1->Height;
si.Right=Image1->Width; PaintBox1->Canvas->CopyRect(si,Image1->Canvas,si); PaintBox1->Canvas->Brush->Style=bsClear;
PaintBox1->Canvas->Pen->Style=psSolid;
PaintBox1->Canvas->Pen->Color=clWhite; PaintBox1->Canvas->Rectangle(Box_x,Box_y,X,Y);
//}
}
這樣可以解決殘影
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |