Topic: [Script] - Short guide to resizing images
Here is a quick tip for resizing images with MVD
This works with jpeg, but you can easily adapt the code for whatever format you want. Just keep in mind that, for what I known now, if working with png you will loose the transparancy with this method.
The code is commented, just drop that on a form with a button, correct the images paths and names (or better add an openfiledialog)
procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
bmp : TBitmap;
jpg : TJpegImage;
scale : Double;
begin
try
//-----> Create the jpeg
jpg := TJpegImage.Create;
try
//-----> assign a file to the jpeg
jpg.LoadFromFile('.\test.jpg');
//-----> if/else to find out which dimension is the larger and set size ratio - I chose 450 but
//you cna choose whatever you want
if jpg.Height > jpg.Width then scale := 450 / jpg.Width else scale := 450 / jpg.Height;
//create the bitmap image
bmp := TBitmap.Create;
try
//-----> define the size of the bitmap
bmp.Width := Round(jpg.Width * scale);
bmp.Height := Round(jpg.Height * scale);
//-----> resize the jpg by loading it into the bitmap with new dimensions
bmp.Canvas.StretchDraw(0,0,bmp.Width,bmp.Height, jpg);
//-----> reassign the bitmpa to the jpeg
jpg.Assign(bmp);
//-----> save the file
jpg.SaveToFile('.\test_thumb.jpg');
except
ShowMessage(ExceptionMessage);
end;
except
ShowMessage(ExceptionMessage);
end;
finally
//Free all images
bmp.Free;
jpg.Free;
end;
end;
Have fun all, this is what is really important after all !!
Cheers
Mathias
Each time I get a divorce, I keep the house
Zaza Gabor