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

Image 的大小

尚未結案
JK53
一般會員


發表:5
回覆:8
積分:2
註冊:2003-12-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-02-26 16:58:06 IP:140.124.xxx.xxx 未訂閱
是有關Image 的放大縮小的問題 程式一開始執行時會有一個預設的Image 大小,(預先描繪一張底圖) 接下來依據資料處理結果的不同將資料描在圖上; Image 的高度也跟著改變 然後可以對這個Image 作存檔的動作 Image 是放置在ScrollBox 裡面的 情況1. 如果預先描繪的Image 底圖大小是400*320 , 則程式剛開啟時Image 大小當然就是400*320 然後處理資料完畢要顯示新圖面時; 假設變成 400*960 則只有最上面部份的400*320 區域會有顯示圖形 Image 的確有拉長了,(ScrollBox 有拉長, 圖面資料也正確) 但下半部剩下的400*640 部份則完全沒有任何顯示 (只有表單本身的顏色) 等於是一張400*960 的Image 跑出來了但下面2/3 的部份是啥都沒有 然後存檔時也只有 上面400*320 的部分能被儲存 情況2. 於是我就將Image 的底圖大小設成 400*3200 (先將它弄的超大的) 然後資料處理完畢要顯示新的Image 時 他也確實依據我所要的大小改變(假設此時Image 顯示已為400*960) 到此為止都很正常 但當我要存檔時 存檔後的圖面大小竟然是整個400*3200的圖形 (當然上面部份的400*960 區域還是有我所要的資料圖形) 等於是一張400*3200 的圖面 , 上半部是我要的資料圖形 大小400*960 但下半部多了一大塊400*2240 的不要的區域 請問該怎麼辦才好
taishyang
站務副站長


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-02-26 17:30:11 IP:140.135.xxx.xxx 未訂閱
JK53您好: 我用下面的code做測試,沒有發現像您一樣的情況耶 在ScrollBox1內放Image1,且將Image1的AutoSize設定成true
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Graphics::TBitmap* BMP = new Graphics::TBitmap();
 BMP->Width=400;
 BMP->Height=320;
 BMP->Canvas->Brush->Color=clBlue;
 BMP->Canvas->FillRect(Rect(0,0,400,320));
 Image1->Picture->Assign(BMP);
 delete BMP;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Graphics::TBitmap* BMP = new Graphics::TBitmap();
  BMP->Width=400;
  BMP->Height=800;
  BMP->Canvas->Brush->Color=clYellow;
  BMP->Canvas->FillRect(Rect(0,0,400,800));
  Image1->Picture->Assign(BMP);
  delete BMP;
}
兩Button交替按下,並不會有您說的情況,或是將您的Code PO上來 好讓前輩們幫您看看 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~
JK53
一般會員


發表:5
回覆:8
積分:2
註冊:2003-12-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-02-26 19:40:11 IP:140.124.xxx.xxx 未訂閱
第一種情形如下:    //---------------------------------------------------------------------------    #include  #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" int height1 = 1 ; //先預設圖面大小比例 int width1 = 1 ; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Image1->Height = height1*320 ; Image1->Width = width1*400 ; Image1->Canvas->Brush->Color = clBlue ; Image1->Canvas->Rectangle(0,0,width1*400,height1*320); Image1->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400)); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { height1 ; width1 ; Image1->Height = height1*320 ; Image1->Width = width1*400 ; Image1->Canvas->Brush->Color = clBlue ; Image1->Canvas->Rectangle(0,0,width1*400,height1*320); Image1->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400)); } //--------------------------------------------------------------------------- 第二種情形如下: //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" int height1 = 12 ; //先預設圖面大小比例 int width1 = 12 ; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Image1->Height = height1*320 ; Image1->Width = width1*400 ; Image1->Canvas->Brush->Color = clBlue ; Image1->Canvas->Rectangle(0,0,width1*400,height1*320); Image1->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400)); height1= 0 ; //將圖面比例歸零 width1= 0 ; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { height1 ; width1 ; Image1->Height = height1*320 ; Image1->Width = width1*400 ; Image1->Canvas->Brush->Color = clBlue ; Image1->Canvas->Rectangle(0,0,width1*400,height1*320); Image1->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400)); } //--------------------------------------------------------------------------- 可能那裡有問題我沒發現吧 還請多多幫忙看一下
taishyang
站務副站長


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-02-26 20:40:28 IP:140.135.xxx.xxx 未訂閱
JK53您好: 同理,將您的程式改成這樣就可以了
int height1 = 1 ; //先預設圖面大小比例
int width1 = 1 ;
Graphics::TBitmap* BMP;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  BMP = new Graphics::TBitmap;
  BMP->Height = height1*320 ;
  BMP->Width = width1*400 ;
  BMP->Canvas->Brush->Color = clBlue ;
  BMP->Canvas->Rectangle(0,0,width1*400,height1*320);
  BMP->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400));
  Image1->Picture->Assign(BMP);    }
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
 height1  ;
 width1  ;
 BMP->Height = height1*320 ;
 BMP->Width = width1*400 ;
 BMP->Canvas->Brush->Color = clBlue ;
 BMP->Canvas->Rectangle(0,0,width1*400,height1*320);
 BMP->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400));
 Image1->Picture->Assign(BMP);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
 delete BMP;
}
//---------------------------------------------------------------------------    或是    int height1 = 1 ; //先預設圖面大小比例
int width1 = 1 ;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  Image1->Picture->Bitmap->Height = height1*320 ;
  Image1->Picture->Bitmap->Width = width1*400 ;
  Image1->Picture->Bitmap->Canvas->Brush->Color = clBlue ;
  Image1->Picture->Bitmap->Canvas->Rectangle(0,0,width1*400,height1*320);
  Image1->Picture->Bitmap->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400));
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
 height1  ;
 width1  ;
 Image1->Picture->Bitmap->Height = height1*320 ;
 Image1->Picture->Bitmap->Width = width1*400 ;
 Image1->Picture->Bitmap->Canvas->Brush->Color = clBlue ;
 Image1->Picture->Bitmap->Canvas->Rectangle(0,0,width1*400,height1*320);
 Image1->Picture->Bitmap->Canvas->TextOutA(0,0,"Height= " IntToStr(height1*320) " Width= " IntToStr(width1*400));
}
//---------------------------------------------------------------------------
順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~ 發表人 -
JK53
一般會員


發表:5
回覆:8
積分:2
註冊:2003-12-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-02-27 11:08:10 IP:140.124.xxx.xxx 未訂閱
謝謝您的幫忙答覆 現在問題已經解決了
系統時間:2024-11-25 23:36:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!