全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2080
推到 Plurk!
推到 Facebook!

請教一下TIamge的問題??

尚未結案
snake720105
一般會員


發表:7
回覆:12
積分:3
註冊:2005-02-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-19 11:32:09 IP:218.32.xxx.xxx 未訂閱
各位先進,我在IMAGE上使用矩形框選,可是卻無法清除前一次所畫的,請問該如何做才可以清除掉,謝謝 輕步玉階飛夜色~~ 不勝蕭然掩月來~~
------
輕步玉階飛夜色~~
不勝蕭然掩月來~~
wu-eric
中階會員


發表:14
回覆:82
積分:64
註冊:2004-03-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-19 11:54:27 IP:220.229.xxx.xxx 未訂閱
這個給你參考 我之前就是用這個做出來的 http://delphi.ktop.com.tw/topic.php?topic_id=36518
wu-eric
中階會員


發表:14
回覆:82
積分:64
註冊:2004-03-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-19 19:53:45 IP:210.66.xxx.xxx 未訂閱
下面這段程式你再試試看是不是你要的 需用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.BottomCanvas->Brush->Style=bsClear;
      PaintBox1->Canvas->Pen->Style=psDot;
      PaintBox1->Canvas->Pen->Color=clBlack;
      PaintBox1->Canvas->Rectangle(grtLTRB);      
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  gbMDown=false;
  PaintBox1->Canvas->CopyRect(Rect(0, 0, PaintBox1->Width, PaintBox1->Height),
                   Image1->Canvas, Rect(0, 0, Image1->Width, Image1->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   gbMDown=false;
   Image1->Picture->LoadFromFile("d:\\Temp\\untitled.bmp"); //載入背景圖片
}
//---------------------------------------------------------------------------    
發表人 - Wu-Eric 於 2005/04/19 19:55:40
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-19 23:18:04 IP:218.168.xxx.xxx 未訂閱
嗯...小弟後來覺得讀一張背景圖片的方式有改進的空間 可以參考下面連結的文章 < href="http://delphi.ktop.com.tw/topic.php?TOPIC_ID=68889">http://delphi.ktop.com.tw/topic.php?TOPIC_ID=68889 利用另外一個Image做繪圖的效果
snake720105
一般會員


發表:7
回覆:12
積分:3
註冊:2005-02-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-04-20 09:03:29 IP:218.32.xxx.xxx 未訂閱
引言: 下面這段程式你再試試看是不是你要的 需用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.BottomCanvas->Brush->Style=bsClear;
      PaintBox1->Canvas->Pen->Style=psDot;
      PaintBox1->Canvas->Pen->Color=clBlack;
      PaintBox1->Canvas->Rectangle(grtLTRB);      
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  gbMDown=false;
  PaintBox1->Canvas->CopyRect(Rect(0, 0, PaintBox1->Width, PaintBox1->Height),
                   Image1->Canvas, Rect(0, 0, Image1->Width, Image1->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   gbMDown=false;
   Image1->Picture->LoadFromFile("d:\\Temp\\untitled.bmp"); //載入背景圖片
}
//---------------------------------------------------------------------------    
發表人 - Wu-Eric 於 2005/04/19 19:55:40
可否說明一下PaintBox在這裡面所扮演的腳色,還未使用過PaintBox這個元件 以下是我的程式碼,但是卻無法清除上一次所畫的,請指教,大大上面所提供的程式碼我之前有下載過類似的範例IMAGERECT,但是卻不知PaintBox與IMAGE成何種關係
 
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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-04-22 17:30:28 IP:218.32.xxx.xxx 未訂閱
我已經可以針對圖面進行框選了,不過有個缺點是框選的時候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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-04-22 17:56:36 IP:61.60.xxx.xxx 未訂閱
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); //} } 這樣可以解決殘影
系統時間:2024-11-23 22:59:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!