2015-01-28 3 views
-1

델파이에서 그림 하나를로드하고 보는 방법을 알고 있습니다. 그러나 파일의 다음 이미지를 가져 오는 '다음 이미지'버튼을 추가하고 싶습니다. 파일에 5 개의 이미지가 있고 다음 버튼을 사용하여 쉽게 스크롤 할 수 있습니다! 나는 다음 버튼을 만들려고 노력했다. 그러나 어떤 코드를 넣어야할지 전혀 모른다!사진을 읽고 단추를 사용하여 사진을 보는 방법 Delphi

감사합니다.

Gpath는 전역 문자열 변수입니다.

procedure TPropertyForm.FormCreate(Sender: TObject); 
begin 
    GPath := getcurrentdir + '\EmployeePhotos\'; 
    EmployeeOpenPictureDialog.InitialDir := getcurrentdir + '\EmployeePhotos'; 

end; 

procedure TPropertyForm.AttatchButtonClick(Sender: TObject); 
var 
    st: string; 
    fsize, psize: integer; 
begin 
    if EmployeeOpenPictureDialog.execute then 
    begin 
    st := EmployeeOpenPictureDialog.FileName; 
    psize := length(GPath); 
    fsize := length(st); 
    Properties.Photo := copy(st, psize + +1, fsize - psize) 
    end { endif }; 

    PhotoImage.Hide; 

    if Properties.Photo <> '' then 
    begin 
    st := GPath + Properties.Photo; 
    if FileExists(st) then 
    begin 
     PhotoImage.Picture.LoadFromFile(st); 
     PhotoImage.Proportional := true; 
     PhotoImage.Show; 
    end 
    { endif } 
    end; { endif } 
end 

procedure TPropertyForm.NextImageButtonClick(Sender: TObject); 
begin 
    PhotoImage.Picture.LoadFromFile(st + 1); 
end; 
+2

당신이의 ImageList를 사용하려고 했이 코드

곳이 TButtons 1 TImage의를하려고하면, "폴더"에서 이미지를로드하고 그들 사이를 전환 할 생각 구성 요소? –

+1

코드가 컴파일되지 않습니다. 이미지 파일의 이름을 알고 있습니까? 당신이 생각하는대로 현재 디렉토리에 의존하지 마십시오. –

+2

하나의 파일에 5 개의 이미지가 있습니까? 어떤 종류의 파일입니까? Delphi 이미지 클래스는 다중 이미지 파일을 기본적으로 지원하지 않으므로 여러 이미지를 처리하고 분리하려면 추가 작업을해야합니다. –

답변

1

나는 당신이 그렇게

  uses jpeg; 
public 
{ Public declarations } 
var 
SL:TStringList; 
ImgIndex:integer; 
GPath:String; 
procedure ListFileDir(Path: string; FileList: TStrings); 
var 
    SR: TSearchRec; 
begin 
    if FindFirst(Path + '*.jpg', faAnyFile, SR) = 0 then 
    begin 
    repeat 
    if (SR.Attr <> faDirectory) then 
     begin 
     FileList.Add(SR.Name); 
     end; 
    until FindNext(SR) <> 0; 
    FindClose(SR); 
    end; 
end; 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
GPath:= getcurrentdir + '\EmployeePhotos\'; 
SL:=TStringList.Create; 
ListFileDir(GPath,SL); 
Image1.Picture.LoadFromFile(GPath + SL.Strings[ImgIndex]); 
end; 

procedure TForm1.btnNextClick(Sender: TObject); 
begin 
ImgIndex:=ImgIndex+1; 
if ImgIndex=SL.Count then ImgIndex :=0; 
Image1.Picture.LoadFromFile(GPath + SL.Strings[ImgIndex]); 
end; 

procedure TForm1.btnPrevClick(Sender: TObject); 
begin 
ImgIndex:=ImgIndex-1; 
if ImgIndex=-1 then ImgIndex :=SL.Count-1; 
Image1.Picture.LoadFromFile(GPath + SL.Strings[ImgIndex]); 
end; 

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
SL.Free; 
end; 
관련 문제