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

TList 使用問題

答題得分者是:taishyang
small7011
一般會員


發表:19
回覆:34
積分:10
註冊:2007-07-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-11-24 15:40:06 IP:211.20.xxx.xxx 訂閱
我的問題是,我動態產生數個image放入list,但是我想要從list個別讀出影像放入image2時會出現無法Assign的問題,可以指導我一下嗎?
[code cpp]
全域變數
TImage *imgArray;
TForm *frmImage;
TList *Component_List;

void __fastcall TForm1::BtnOpenBmpClick(TObject *Sender)
{
Graphics::TBitmap* BMP = new Graphics::TBitmap();
OpenDialog1->Filter = "Bmp (*.bmp)|*.Bmp"; //Only Open .DAT File
OpenDialog1->Options.Clear();
if (OpenDialog1->Execute()){
BMP->LoadFromFile(OpenDialog1->FileName);
StatusBar1->Panels->Items[5]->Text=OpenDialog1->FileName;
}
else{
ShowMessage(" OPEN FILE FAIL!!");
return;
}
Image1->Height=BMP->Height;
Image1->Width=BMP->Width;
Image1->Picture->Assign(BMP);
ImageOutput(BMP,BMP->Height);
frmImage->ShowModal();
}
void __fastcall TForm1::ImageOutput(Graphics::TBitmap* pBmp,int iScanLine)
{
//*************Output To User Interface*****************
frmImage=new TForm(Application); //Dynamic Create Form
Component_List= new TList();
//Create TShape Component
int iPos=0,iInspectSize=800;
int PixelCount=10320;
TRect Rect_Bmp,Rect_Img;
for(int ImageIndex=0;PixelCount>0;ImageIndex )
{
imgArray = new TImage(this);
imgArray->Parent = frmImage;
imgArray->Left=1;
imgArray->Top=iPos;
imgArray->Width=iInspectSize;
imgArray->Height=iScanLine;
imgArray->Name="Photo" IntToStr(ImageIndex 1);
imgArray->Tag=ImageIndex;

if(PixelCount>=iInspectSize){
Rect_Bmp = Rect(iInspectSize*ImageIndex 1,1,iInspectSize*(ImageIndex 1),imgArray->Height);//Src
Rect_Img = Rect(1,1,iInspectSize,imgArray->Height);
PixelCount-=iInspectSize;
}
else
{
Rect_Bmp = Rect(iInspectSize*ImageIndex 1,1,(iInspectSize*ImageIndex PixelCount),imgArray->Height);
Rect_Img = Rect(1,1,PixelCount,imgArray->Height);
imgArray->Canvas->Brush->Color=clSkyBlue;
imgArray->Canvas->Brush->Style=bsDiagCross;
imgArray->Picture->Bitmap->Canvas->FillRect(Rect(1,1,imgArray->Width,imgArray->Height));
PixelCount=0;
}
imgArray->Canvas->CopyRect(Rect_Img,pBmp->Canvas,Rect_Bmp); //Copy Image
Component_List->Add(imgArray);
iPos =iScanLine 5;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image2->Left=1;
Image2->Top=1;
Graphics::TBitmap* Bmp1 = new Graphics::TBitmap();

//為什麼無法從list中讀出影像,填入Image2
Image2->Picture->Assign((TImage*)Component_List->Items[0]);
delete Bmp1;
}

請在此區域輸入程式碼
[/code]
------
lee
編輯記錄
small7011 重新編輯於 2008-11-24 15:41:39, 註解 無‧
small7011 重新編輯於 2008-11-24 15:43:20, 註解 無‧
small7011 重新編輯於 2008-11-24 15:45:31, 註解 無‧
small7011 重新編輯於 2008-11-24 15:47:09, 註解 無‧
herbert2
尊榮會員


發表:58
回覆:640
積分:894
註冊:2004-04-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-11-24 16:02:50 IP:211.72.xxx.xxx 訂閱
TList 存的應是 TObject 的 Pointer, 您這種用法似乎不可行!
若用 TStrings 做 Component_List 存 00~FF (各 Byte ASCII, 但可能 Strings[i] 有 64KB 或 2GB 限制),
再將 Component_List->Items[1] 逆轉回 TImage, 不知是否行得通.

taishyang
站務副站長


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-11-24 16:15:37 IP:118.169.xxx.xxx 訂閱
試試
Image2->Picture->Assign(((TImage*)Component_List->Items[0])->Picture);

我用下面的code測試的
TList *ls = new TList;
TImage *img = new TImage(this);
img->Parent = this;
img->Width = 50;
img->Height = 50;
img->Canvas->TextOutA(0, 0, "PIC");
img->Canvas->Brush->Color = clRed;
img->Canvas->FillRect(img->ClientRect);
ls->Add((TImage*)img);
Image2->Picture->Assign(((TImage*)ls->Items[0])->Picture);
delete img;
delete ls;
small7011
一般會員


發表:19
回覆:34
積分:10
註冊:2007-07-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-11-24 16:45:47 IP:211.20.xxx.xxx 訂閱
謝謝您Taishyang,我已經可以順利從Tlist 讀出我所存的元件,真的很感謝
===================引 用 taishyang 文 章===================
試試
Image2->Picture->Assign(((TImage*)Component_List->Items[0])->Picture);

我用下面的code測試的
TList *ls = new TList;
TImage *img = new TImage(this);
img->Parent = this;
img->Width = 50;
img->Height = 50;
img->Canvas->TextOutA(0, 0, "PIC");
img->Canvas->Brush->Color = clRed;
img->Canvas->FillRect(img->ClientRect);
ls->Add((TImage*)img);
Image2->Picture->Assign(((TImage*)ls->Items[0])->Picture);
delete img;
delete ls;
------
lee
系統時間:2024-04-24 23:15:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!