jus
-
Content Count
3 -
Joined
-
Last visited
Posts posted by jus
-
-
ok, maybe it would be clearer with code.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ImgList, ComCtrls; type TForm1 = class(TForm) ListView1: TListView; ImageList1: TImageList; procedure FormCreate(Sender: TObject); private procedure ListFileDir(Path: string; FileList: TStrings); public { Public-Deklarationen } end; const PrintPreviewPixelSize = 100; var Form1: TForm1; implementation {$R *.dfm} uses jpeg; procedure CreateThumbnailFromFile(const FileName: String; var OutBmp: TBitmap); var Picture: TPicture; InBmp: TBitmap; begin OutBmp.Assign(nil); Picture := TPicture.Create; try Picture.LoadFromFile(FileName); InBmp:=Tbitmap.Create; try InBmp.Width := Picture.Width; InBmp.Height := Picture.Height; InBmp.Canvas.Draw(0, 0, Picture.Graphic); OutBmp.Width := PrintPreviewPixelSize; OutBmp.Height := PrintPreviewPixelSize; SetStretchBltMode(OutBmp.Canvas.Handle, HALFTONE); StretchBlt(OutBmp.Canvas.Handle, 0, 0, PrintPreviewPixelSize, PrintPreviewPixelSize, InBmp.Canvas.Handle , 0, 0, InBmp.Width , InBmp.Height , SRCCOPY); finally InBmp.Free; end; finally Picture.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); var I: Integer; ListItem: TListItem; FileList: TStringList; BmpOut: TBitmap; begin ImageList1.Height := PrintPreviewPixelSize; ImageList1.Width := PrintPreviewPixelSize; FileList := TStringList.Create; try ListFileDir('d:\a\2010.10\', FileList); BmpOut := TBitmap.Create; try for I := 0 to Pred(FileList.Count) do begin CreateThumbnailFromFile(FileList.Strings[i], BmpOut); ImageList1.Add(BmpOut, nil); end; finally BmpOut.Free; end; finally FileList.Free; end; ListView1.LargeImages := ImageList1; for I := 0 to ImageList1.Count - 1 do begin ListItem := ListView1.Items.Add; Listitem.Caption := 'Image' + IntToStr(I); ListItem.ImageIndex := I; end; end; procedure TForm1.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(Path+SR.Name); end; until FindNext(SR) <> 0; FindClose(SR); end; end; end.
Currently I have a method called "CreateThumbnailFromFile" (see above) which convert a jpeg file into a bitmap for adding to an TImageList. In my original method it does a little bit more, but it doesn't matter. My intention is to put the CreateThumbnailFromFile method to a background task something like
for I := 0 to Pred(FileList.Count) do begin CreateTask(CreateThumbnailFromFile(FileList.Strings[i], BmpOut)); end;
and in the OnTerminate I can add the BmpOut (TBitmap) to the TImageList. The thing I don't know is how can I retrieve the BmpOut (TBitmap) in an OnTerminate method in OmniThreadLibrary?
Could anyone can give me a hint?
-
Hi,
i'm using Delphi 2007 and I want to put some graphics stuff into background tasks. The result of that function is a TBitmap. On higher Delphi versions there is seems a Async method with OnTerminate. But how can I retrieve the TBitmap result from a lowlevel task after finishing in the main thread?
Thank you in advance!
jus
how get results back from a low level task?
in OmniThreadLibrary
Posted · Edited by jus
ok, thank you for your help. Finally I decided to use the sending object concept from the \OmniThreadLibrary\tests\23_BackgroundFileSearch. It seems to work in my Delphi 2007. Here is my implementation for the case if someone has a similiar topic:
There is one thing I didn't solved. If I close the App during creating the thumbnails there would be some access violations. How would you extend the program to terminate the tasks and delete the threadpool queue?
jus
ListViewMiniThread.zip