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

load進bmp後,什麼動作都不能做

尚未結案
GeorgeZ
一般會員


發表:4
回覆:1
積分:1
註冊:2004-05-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-17 01:21:26 IP:140.125.xxx.xxx 未訂閱
上圖開了我這兩個同樣的程式。左上、右下。 左上: 在主form還沒load進bmp時,主form秀出的第二個form, 按下page1的按扭後可以正常執行。 右下: load進一個20mb左右的圖後(事實上,就算load進一個只到1mb的圖,情況也是相同) 就會出現錯誤訊息->list index out of bound(1)-->(做Tstringlist的運算出現的錯誤)。 試過,不管讀進TXT檔(can't open file"...txt")或連接手機(can find device) ,在已開圖的狀況下,都會出現錯誤。在未開圖的情況下都正常。 另外,也試過在開圖的情況下,把會錯誤的的動作移到主form的"座標"這個按扭去做, 而不讓次要的form出來,卻也會發生錯誤 TOT。看來是第一個FORM的程式有問題… 可是我裡面沒寫什麼啊 +_+||| 第一個FROM的CODE如下。請各位長輩幫忙一下,感激不盡。
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include "Unit1.h"
//#include "Unit1.cpp"
TMainForm *MainForm;
Graphics::TBitmap *Bmp = new Graphics::TBitmap();    //---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{    }
//---------------------------------------------------------------------------    void __fastcall TMainForm::N2Click(TObject *Sender)
{
 OpenPictureDialog1->Filter = GraphicFilter(__classid(Graphics::TBitmap));
  if (OpenPictureDialog1->Execute())
  {
     Bmp->Dormant();           // Free up GDI resources
     Bmp->FreeImage();         // Free up Memory
     Bmp->ReleaseHandle();
     Bmp->LoadFromFile(OpenPictureDialog1->FileName);         Image1->Width  = Bmp->Width;
     Image1->Height = Bmp->Height;
     Image1->Picture->Bitmap = Bmp;         Bmp->Canvas->Rectangle(0,0,Bmp->Width,Bmp->Height);
     StatusBar1->Panels->Items[1]->Text=IntToStr(Bmp->Width)+" x "+IntToStr(Bmp->Height);
  }
}
//---------------------------------------------------------------------------    void __fastcall TMainForm::N3Click(TObject *Sender)
{
  Bmp->Dormant();
  Bmp->FreeImage();
  Bmp->ReleaseHandle();
  delete Bmp;
  //Image1->Picture->Bitmap = Bmp;
  //Image2->Picture->Bitmap = Bmp;
}
//---------------------------------------------------------------------------    void __fastcall TMainForm::N4Click(TObject *Sender)
{
if (Image1->Picture->Bitmap->Empty==true)
     ShowMessage("no Image to Save");
 else
 {
  SavePictureDialog1->Filter = GraphicFilter(__classid(Graphics::TBitmap));
  if (SavePictureDialog1->Execute())
  {
     Image1->Picture->SaveToFile(SavePictureDialog1->FileName + ".bmp");      }
 }        
}
//---------------------------------------------------------------------------    void __fastcall TMainForm::N5Click(TObject *Sender)
{
   delete Bmp;
   exit(0);        
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PaintBox1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{     if (Image1->Picture->Bitmap->Empty==false)
  {       PaintBox1->Canvas->CopyRect(PaintBox1->ClientRect, Image1->Canvas,
      Image1->ClientRect);
   PaintBox1->Canvas->Brush->Style=bsClear;
   PaintBox1->Canvas->Pen->Style=psDot;
   PaintBox1->Canvas->Pen->Color=clBlack;
   PaintBox1->Canvas->MoveTo(X, 0);
   PaintBox1->Canvas->LineTo(X, PaintBox1->Height);
   PaintBox1->Canvas->MoveTo(0, Y);
   PaintBox1->Canvas->LineTo(PaintBox1->Width, Y);
   StatusBar1->Panels->Items[0]->Text="X:"+IntToStr(X)+" " + "Y:"+IntToStr(Y);
   //StatusBar1->Panels->Items[1]->Text="Y:"+IntToStr(Y);
   //StatusBar1->Panels->Items[0]->Text=X;//"X:" + X;
   //StatusBar1->Panels->Items[1]->Text=Y;//"Y:" + Y;       }
   
}
//---------------------------------------------------------------------------    void __fastcall TMainForm::StatusBar1DrawPanel(TStatusBar *StatusBar,
      TStatusPanel *Panel, const TRect &Rect)
{
      AnsiString sz;
   if(Panel->Index==0)
   {
      //StatusBar1->Canvas->Brush->Color=clYellow;
      StatusBar1->Canvas->Font->Name="X";
      //StatusBar1->Canvas->Font->Color=clBlue;
      sz="X:";
   }
   else if(Panel->Index==1)
   {
      //StatusBar1->Canvas->Brush->Color=clGreen;
      StatusBar1->Canvas->Font->Name="Y";
      //StatusBar1->Canvas->Font->Color=clRed;
      sz="Y:";
   }
   else if(Panel->Index==2)
   {
      //StatusBar1->Canvas->Brush->Color=clGreen;
      StatusBar1->Canvas->Font->Name="標楷體";
      //StatusBar1->Canvas->Font->Color=clRed;
      sz="1";
   }
   //StatusBar1->Canvas->FillRect(Rect);
  // StatusBar1->Canvas->Brush->Style=bsClear;
   //StatusBar1->Canvas->TextOutA(Rect.Left+2, Rect.Top+2, sz);    }
//---------------------------------------------------------------------------    void __fastcall TMainForm::N7Click(TObject *Sender)
{
PhoneOP->Show();
}
//---------------------------------------------------------------------------         
發表人 - GeorgeZ 於 2004/05/17 01:32:21 發表人 - taishyang 於 2004/05/17 15:39:19
GeorgeZ
一般會員


發表:4
回覆:1
積分:1
註冊:2004-05-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-17 02:27:31 IP:140.125.xxx.xxx 未訂閱
嗯…發現是OpenPictureDialog的問題… 若是在程式執行時自動先LOAD進圖,就不會有這種情況 但 為啥呢@@?
系統時間:2024-06-29 13:22:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!