Resize image on to new canvas

Example requests & Code samples for GdPicture Toolkits.
Post Reply
varcarme
Posts: 40
Joined: Tue Feb 05, 2008 8:56 pm

Resize image on to new canvas

Post by varcarme » Sat Feb 20, 2010 1:12 pm

I wondered if you could point me in the right direction with this....

I want to take a number of images (with different dimensions) fit a given template / canvas but keeping it's height / width ratio and without losing any quality.

I have tried using the ResizeHeightRatio() / ResizeWidthRatio() functions but although the resulting image seems reduced (in terms of pixel size), GetHeightmm() and GetWidthmm() still return the same dimensions of the original image. The resulting image also has a small DPI count.

Lets say I have an Image that is 1000 pixels wide x 1000 pixels high (300 DPI) and I want to make it fit an area / canvas of 800w x 600h....i.e. the resulting image would need to be 600 x 600, centered (i.e 200 pixels white space at either side)

I think instead I need to possibly create a new image with the correct dimensions and then shrink the original to fit inside the new canvas using DrawImage().

Is this correct?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Resize image on to new canvas

Post by Loïc » Mon Feb 22, 2010 10:33 am

Hi,

Code: Select all

I think instead I need to possibly create a new image with the correct dimensions and then shrink the original to fit inside the new canvas using DrawImage().
Yes, it is the best way :)
Let me know if you need an example.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest