Se plantea el problema de cómo generar lo que normalmente llamamos un
"thumbnail" de una imagen que tenemos guardada en un fichero. Añadiendo un poco más de código podríamos generar todos los
"thumbnail" de las imagenenes que hay en el directorio. Para ello se utiliza un componente TBitmap.
Vamos con el código:
Código Delphi
[-]
var
bmp: TBitmap;
jpg: TJpegImage;
scale: Double;
begin
if opendialog1.execute then
begin
jpg := TJpegImage.Create;
try
jpg.Loadfromfile(opendialog1.filename);
if jpg.Height > jpg.Width then
scale := 50 / jpg.Height
else
scale := 50 / jpg.Width;
bmp := TBitmap.Create;
try
bmp.Width := Round(jpg.Width * scale);
bmp.Height := Round(jpg.Height * scale);
bmp.Canvas.StretchDraw(bmp.Canvas.Cliprect, jpg);
Self.Canvas.Draw(100, 10, bmp);
jpg.Assign(bmp);
jpg.SaveToFile(ChangeFileext(opendialog1.filename, '_thumb.JPG'));
finally
bmp.free;
end;
finally
jpg.free;
end;
end;
Se necesita un form con un control
OpenDialog para abrir el fichero de imagen (JPG).
Y la Unit
jpeg en el uses.