Vampyre Imaging Library Forum

Imaging Category => Help & Questions => Topic started by: pka4916 on 5 January 2010, 16:00:39

Title: Load / Save image with resize ?
Post by: pka4916 on 5 January 2010, 16:00:39
I'm kinda confused

when I load a image into a Timage  and save it, then the file gets really big
the input is a jpg 250Kb  and the output a PNG  1.8 Mb
why?

This is what I used

Code (delphi) Select
FImage := TSingleImage.Create;
ConvertBitmapToImage(Timage1Picture.Bitmap, FImage);
FImage.SaveToFile('c:\test.png');


I must say, that I nowhere set something that it  needs to be a PNG file.
maybe that's it... but where do I need to put it and what?

also  the image =  1200x800
i am loading it into the Timage  at  320x240  and have it set to fix so i can see the whole thing.

how can i save it with that sizeformat?   now when I save it's still 1200x800

thank you very much
Title: Re: Load / Save image with resize ?
Post by: Galfar on 6 January 2010, 17:29:37
JPEG uses lossy compression - it throws away some image information away and it's never going back.
PNG on the other hand uses lossless compressions - so no information is lost during compression.
So It's to be expected that the same image in PNG file would take up more disk space than JPEG.

TImage just displays assigned TGraphic/TBitmap, it doesn't modify it in any way. You need to resize the bitmap manualy (from your code sample - either Timage1Picture.Bitmap.SetSize or FImage.Resize).
Title: Re: Load / Save image with resize ?
Post by: pka4916 on 6 January 2010, 17:44:38
if i use the Timage1Picture.Bitmap.SetSize  then it just grabs that piece from the picture (org size 1280x1800).  even though it shows the full pic inside the Timage.

Tried also the FImage.Resize  but then the original Aspect Ratio is not correct anymore.
Title: Re: Load / Save image with resize ?
Post by: Galfar on 6 January 2010, 17:53:06
Just keep the aspect ratio in mind when resizing.

aspectratio := FImage.width / FImage.height; 
FImage.Resize(img, newwidth, newwidth / aspectratio, rfBicubic); 
Title: Re: Load / Save image with resize ?
Post by: pka4916 on 6 January 2010, 18:29:55
Delphi doesn't take that.     Extended vs Integer
Did a Round( )    but then the ratio = 1  so  ain't right.
Title: Re: Load / Save image with resize ?
Post by: Galfar on 6 January 2010, 19:05:42
Do the Round on newwidth / aspectratio, not on FImage.width / FImage.height.
Aspectratio variable should be real number.

var aspectratio: Single;
aspectratio := FImage.width / FImage.height; 
FImage.Resize(img, newwidth, Round(newwidth / aspectratio), rfBicubic);