線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2770
推到 Plurk!
推到 Facebook!

bitmap物件assign給TImage的方法差異

答題得分者是:william
JerryKuo
版主


發表:42
回覆:571
積分:322
註冊:2003-03-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-11 11:51:09 IP:61.230.xxx.xxx 未訂閱
各位好:    請問一下 Bmp->LoadFromFile(OpenPictureDialog1->FileName); Image1->Width  = Bmp->Width; Image1->Height = Bmp->Height; Image1->Canvas->Draw(0,0,Bmp); <-方法一 Image1->Picture->Bitmap = Bmp; <-方法二 當使用方法一時,第一次開啟256x256的圖,處理完再開啟512x512的圖 結果秀出的圖片左上角只有左上角256x256那一塊。若改成方法二就 可以秀出整張圖,完全不受前一次開啟圖片大小所影響。 所以如果要使用方法一,又要得到和方法二一樣的效果,是否可以增加 一些設定就可以達成呢?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-11 13:58:40 IP:147.8.xxx.xxx 未訂閱
It is because the Canvas of a TImage is actually the canvas of an bitmap owned by the image. A bitmap with same size of the TImage will be created upon the very first access to the TImage.Canvas. Any changes to the Width and Height properties of the TImage will not affect the size of the internal bitmap afterward. Your 方法二 is actually an assign of your bitmap (i.e. Image1->Picture->Bitmap->Assign(Bmp)), so the size is correct.    Try this for 方法一: Image1->Width = Bmp->Width; Image1->Height = Bmp->Height; Image1->Picture->Bitmap->Width = Bmp->Width; Image1->Picture->Bitmap->Height = Bmp->Height; Image1->Canvas->Draw(0,0,Bmp);
taishyang
站務副站長


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-11 14:05:56 IP:140.135.xxx.xxx 未訂閱
JerryKuo您好:   試試
 
 Image1->AutoSize=true;
 Bmp->LoadFromFile(OpenPictureDialog1->FileName);
 Image1->Picture->Bitmap->Width = Bmp->Width;
 Image1->Picture->Bitmap->Height = Bmp->Height;
 Image1->Canvas->Draw(0,0,Bmp);// <-方法一
// Image1->Picture->Bitmap = Bmp;// <-方法二
 delete Bmp;
順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
JerryKuo
版主


發表:42
回覆:571
積分:322
註冊:2003-03-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-14 12:45:14 IP:210.68.xxx.xxx 未訂閱
先謝版主和william的幫忙,加了這兩行就可以使用 Image1->Picture->Bitmap->Width = Bmp->Width; Image1->Picture->Bitmap->Height = Bmp->Height; 從答案來看,是不是image物件還包涵了一個bitmap的物件? 如果要改變image的大小,將圖片秀出,則必須兩個物件同時 更改。
taishyang
站務副站長


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-14 12:52:51 IP:140.135.xxx.xxx 未訂閱
我自己測試的結果要加上   
Image1->AutoSize=true;
才行< > 個人感覺是 > 順心< > <>~我也是在學習的階段,所以請您多多見諒與指教~
系統時間:2024-04-29 3:50:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!