TList 使用問題 |
答題得分者是:taishyang
|
small7011
一般會員 發表:19 回覆:34 積分:10 註冊:2007-07-24 發送簡訊給我 |
我的問題是,我動態產生數個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 |
herbert2
尊榮會員 發表:58 回覆:640 積分:894 註冊:2004-04-16 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
試試
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 發送簡訊給我 |
謝謝您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 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |