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

關於影像的複製還有顯示

答題得分者是:richtop
bcb6
一般會員


發表:4
回覆:5
積分:1
註冊:2004-08-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-08 17:17:07 IP:140.116.xxx.xxx 未訂閱
void __fastcall TForm1::Button_openfileClick(TObject *Sender) { if(OpenDialog1->Execute()) { temp1=new Graphics::TBitmap(); temp2=new Graphics::TBitmap(); temp1->LoadFromFile(OpenDialog1->FileName); temp2->LoadFromFile(OpenDialog1->FileName); Image1->Width=Width=temp1->Width; Image1->Height=Height=temp1->Height; Image1->Picture->Assign(temp1); } } void __fastcall TForm1::Button_resetClick(TObject *Sender) { temp1=temp2; Image1->Picture->Assign(temp1); Form1->Refresh(); } 可以直接用temp1=temp2嗎? 另外 Image1->Picture->Assign(temp1);的意思是複製temp1到Image1上嗎? 我在Button_reset想要做到 回復原來的圖片 可是這樣寫好像有錯誤 因為達不到我要的功能 不知道要怎樣寫呢?假如temp2是原來的圖形,temp1是做過影像處理之後的圖片。且影像處理都在temp1上面做 temp2是用來回復原圖的。
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-08 20:45:02 IP:61.230.xxx.xxx 未訂閱
 
// 修改後
void __fastcall TForm1::Button_openfileClick(TObject *Sender)
{
if(OpenDialog1->Execute())
{
temp1=new Graphics::TBitmap();
temp2=new Graphics::TBitmap();
temp1->LoadFromFile(OpenDialog1->FileName);
temp2->Assign(temp1); //可省讀磁碟的時間
Image1->Width=Width=temp1->Width;   
Image1->Height=Height=temp1->Height;
Image1->Picture->Assign(temp1);
}
}
void __fastcall TForm1::Button_resetClick(TObject *Sender)
{
Image1->Picture->Assign(temp2); //從temp2 load 進來
Form1->Refresh();
}
可以直接用temp1=temp2嗎? ans:假如要複製圖,不能? 另外 Image1->Picture->Assign(temp1);的意思是複製temp1到Image1上嗎? ans:YES 我在Button_reset想要做到 回復原來的圖片 可是這樣寫好像有錯誤 因為達不到我要的功能 不知道要怎樣寫呢?假如temp2是原來的圖形,temp1是做過影像處理之後的圖片。且影像處理都在temp1上面做 temp2是用來回復原圖的。 ans:直接Assign(temp2)不就好了.你用temp1=temp2;假如temp1沒先存起來,會有一些記憶體無法delete.
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-09-08 21:00:46 IP:211.76.xxx.xxx 未訂閱
bcb6 您好:    
引言: void __fastcall TForm1::Button_openfileClick(TObject *Sender) { if(OpenDialog1->Execute()) { temp1=new Graphics::TBitmap(); temp2=new Graphics::TBitmap(); //temp1->LoadFromFile(OpenDialog1->FileName); temp2->LoadFromFile(OpenDialog1->FileName); temp1->Assign(temp2); Image1->Width=Width=temp1->Width; Image1->Height=Height=temp1->Height; Image1->Picture->Assign(temp1); } } void __fastcall TForm1::Button_resetClick(TObject *Sender) { temp1=temp2; Image1->Picture->Assign(temp1); Form1->Refresh(); } 可以直接用temp1=temp2嗎? 理論上可以,不過有兩種情況: 1.
  
  Graphics::TBitmap *temp1 = NULL; // 這時temp1只是一個指標變數,系統未配置實際儲存TBitmap的空間。
  Graphics::TBitmap *temp2 = new Graphics::TBitmap(); // temp2指向系統所配置儲存TBitmap的記憶體空間。      temp1 = temp2; // 這時temp1,temp2指向相同的TBitmap記憶體空間
2.
  
  Graphics::TBitmap *temp1 = new Graphics::TBitmap();
  Graphics::TBitmap *temp2 = new Graphics::TBitmap();
  // 此時,temp1,temp2分別指向系統所配置儲存TBitmap的記憶體空間。
  
  temp1 = temp2; // 語法OK,因為temp1是一個指標,所以其內容(所存放的位址)會等於temp2的內容,因此temp1原先所指向系統配置的TBitmap記憶體空間位址,如今該值被temp2的值取代了,雖然語法仍對,但之前temp1所指的那塊記憶體空間,也就無法被釋放了,將造成記憶體漏失。
另外 Image1->Picture->Assign(temp1);的意思是複製temp1到Image1上嗎? 是複製沒錯! 我在Button_reset想要做到 回復原來的圖片 可是這樣寫好像有錯誤 因為達不到我要的功能 不知道要怎樣寫呢?假如temp2是原來的圖形,temp1是做過影像處理之後的圖片。且影像處理都在temp1上面做 temp2是用來回復原圖的。 依您的描述,temp1,temp2應該要各自有各自的記憶體空間,即case 2。 所以這時就不能使用 temp1 = temp2; 而該使用 temp1->Assign(temp2); 來將temp2複製到temp1。
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
系統時間:2024-06-28 1:43:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!