Re: Out of system resources
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Thu, 16 Nov 2006 23:51:21 +0100
"Bjørge" <bjorge@xxxxxxx> schreef in bericht
news:fZqdnW2LjbETeMHYRVnzvA@xxxxxxxxxxxxxx
I believe you'll have to post a little more of your code...the
Thread.Execute; method, for instance.
I have to bring it down to essentials: JPG files only. TggThread is of
class(Tthread).
Results of some experimenting: a list of 60 large photo's (up to 1Mb) is
processed correctly, time and again. Another list of 10 small photo's
(<50kb) fails every now and then, but not always at the same photo.
type
TphotoRec = class
sourceFile : string;
targetFile : string;
targetWidth : integer;
targetHeight : integer;
end;
TphotoCopyThread= class(Tggthread)
sourceDir : string;
targetDir : string;
photoList : Tlist;
constructor Create(initiatorAddress : TggThread);
protected
procedure Execute; override;
end;
procedure CopyImageToBitmap(sourceFile : string; bitmap : Tbitmap; rect :
Trect);
// stretchdraw from source file to bitmap
var
picture : Tpicture;
begin
picture:=Tpicture.create;
try
try
Picture.LoadFromFile(sourceFile);
except
exit
end;
bitmap.Width:=rect.Right;
bitmap.Height:=rect.Bottom;
bitmap.Canvas.StretchDraw(rect,Picture.Graphic);
finally
picture.free
end;
end;
procedure CopyImageToSize(sourceFile,destinationFile : string; width,height
: integer);
// Read sourceFile and extract to bitmap in predetermined scale.
// Export to jpg.
var
ext : string;
bitmap : Tbitmap;
JPGimage : TjpegImage;
rect : Trect;
begin
bitmap:=Tbitmap.Create;
try
rect.Left:=0;
rect.Right:=width;
rect.Top:=0;
rect.Bottom:=height;
ext:=Uppercase(extractFileExt(sourceFile));
if (ext='.JPG') OR (ext='.JPEG') OR (ext='.BMP')
then CopyImageToBitmap(sourceFile,bitmap,rect)
else ; // skipped for this post
JPGimage:=TjpegImage.Create;
try
JPGimage.Assign(bitmap);
JPGimage.CompressionQuality:=60;
JPGimage.SaveToFile(destinationFile); // <------- if ERROR, then it
will happen here
except
end;
JPGimage.free
finally
bitmap.free
end;
end;
constructor TphotoCopyThread.Create(initiatorAddress: TggThread);
begin
inherited;
photoList:=Tlist.create;
end;
procedure TphotoCopyThread.Execute;
var
k : integer;
targetDir : string;
photo : TphotoRec;
begin
if photoList.Count=0
then exit;
targetDir:=ExtractFilePath(TphotoRec(photoList[0]).targetFile);
if NOT directoryExists(targetDir)
then CreateDir(targetDir);
for k:=0 to photoList.Count-1 do
begin photo:=TphotoRec(photoList[k]);
CopyImageToSize(photo.sourceFile,photo.targetFile,
photo.targetWidth,photo.targetHeight);
photo.Free;
end;
photoList.Free;
end;
.
- Follow-Ups:
- Re: Out of system resources
- From: Bart
- Re: Out of system resources
- References:
- Out of system resources
- From: Tom de Neef
- Re: Out of system resources
- From: Bjørge
- Out of system resources
- Prev by Date: Re: Out of system resources
- Next by Date: Re: Components at Design Time - moving and resizing
- Previous by thread: Re: Out of system resources
- Next by thread: Re: Out of system resources
- Index(es):
Relevant Pages
|