VoyForums

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 123456[7]8910 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 10:46:01 10/31/01 Wed
Author: Tim Griffin
Subject: Re: How to create an application to have thumbnails?
In reply to: ANDREW DIABO 's message, "How to create an application to have thumbnails?" on 16:23:21 10/25/01 Thu

Here's a Delphi 5 procedure that makes thumbnails.
I'm also looking forward to seeing Michel's example.

This procedure even expands pictures with Michel's interpolation routines if the requested 'thumbnail' is larger than the original picture (cool Michel, thanks for the functionality!).

The first 2 parameters provide the input filename and the output filename of a JPG image.

The last 4 parameters specify the size of the 'thumbnail'.
- Use MaxH and MaxW to specify the max. number of pixels per side (I use these to resize pictures to fit them on a PC screen). Example: 768,1024,0,0 -or- 600,800,0,0.
- or Use MinH and MinW to specify the min. number of pixels per side (I use these for my 'real' thumbnails). Example: 0,0,150,150.

The only other thing that's needed on a Delphi form to make this work is a TImageScrollBox (ImageScrollBox1) which can be invisible.


Procedure CreateThumbnail2(InFileName, OutFileName: string;
maxh, maxw, minh, minw:longint);
var
Transform : TResizeTransform;
ratio : real;
h,w : longint;
JPGGraphic : TJpegGraphic;

begin
if (not fileexists(outfilename)) or (filesiz(outfilename) < 1) or
(fileage(outfilename) <= fileage(infilename))
then begin
with form1 do begin
JPGGraphic := TJpegGraphic.Create;
Transform := TResizeTransform.Create;

ImageScrollBox1.LoadFromFile(InFileName,0);

JPGGraphic.assign(ImageScrollBox1.Graphic);
TJpegGraphic(JPGGraphic).SaveQuality := thumbs2jpgquality;

h := ImageScrollBox1.Graphic.Height;
w := ImageScrollBox1.Graphic.Width;

ratio := 0;
if maxh > 0 then begin
if (maxh / h) < (maxw / w) then
ratio := maxh / h
else
ratio := maxw / w;
end;

if minh > 0 then begin
if (minh / h) > (minw / w) then
ratio := minh / h
else
ratio := minw / w;
end;

try
if ratio > 1 then begin
Transform.Interpolated := true;
Transform.Filter := TInterpolationFilter(0); // Triangle
end;

Transform.Width := round(w * ratio);
Transform.Height := round(h * ratio);
Transform.ApplyOnDest(JPGGraphic, ImageScrollBox1.Graphic);

ImageScrollBox1.SaveToFile(OutFileName);
finally
JPGGraphic.free;
Transform.Free;
end;
end;
end;
end;

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.