bitmap物件assign給TImage的方法差異 |
答題得分者是:william
|
JerryKuo
版主 ![]() ![]() ![]() ![]() ![]() 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
各位好: 請問一下
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 發送簡訊給我 |
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 發送簡訊給我 |
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 發送簡訊給我 |
|
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |