• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Load / Save image with resize ?

Started by pka4916, 5 January 2010, 16:00:39

Previous topic - Next topic

pka4916

5 January 2010, 16:00:39 Last Edit: 20 January 2010, 22:18:37 by Galfar
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

Galfar

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).

pka4916

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.

Galfar

Just keep the aspect ratio in mind when resizing.

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

pka4916

Delphi doesn't take that.     Extended vs Integer
Did a Round( )    but then the ratio = 1  so  ain't right.

Galfar

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);

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk