Image Transformation

S

Stimp

I've been hacking at this for 15 mins, but haven't really got too much
time to spend on it today, so maybe someone here can suggest a quick
fix or suggest if there is a function built into asp.net that I could
look at...

Say I have an image that's 600 x 480 pixels and I want to create a new
image which is cropped from this image to something like 100 x 80
pixels.

The only problem is that the new image must show the full width of the
original image, plus the image should be centered height-wise (i.e.
cropping off the top and bottom of the original image)

Essentially I have 2 rectangles, one for the src image and the other for
the output image.

Using the above example, the output image rectangle is:

(0, 0, 100, 80) - creates an image 100 x 80 pixels, starting at 0,0

and so far I've got the following for the src rectangle:

(0, iSrcY , imgOrig.Width, iSrcHeight)

The values I need here are: iSrcY (the starting point on the y-axis)
iSrcHeight (the height of the source image to take)

these would be calculated using a ratio derived from the size
of the destination image i.e. 100 x 80

Any ideas, or is there an asp.net transformation function built in that
I can use?

Thanks!
 
P

Peter Rilling

Do you want to crop or scale? Cropping means chopping off parts of the
image so that it is no longer visible while scaling simply shrinks or
enlarges while keeping the relative dimensions in tacked while keeping the
image whole.
 
S

Stimp

Do you want to crop or scale? Cropping means chopping off parts of the
image so that it is no longer visible while scaling simply shrinks or
enlarges while keeping the relative dimensions in tacked while keeping the
image whole.

Well I want to basically resize the image to the width of the new
rectangle (i.e. 100 pixels), but then to crop this new image around the
centre with a crop height of 80 pixels (or whatever value the target
rectangle is)

The new image must be in the same aspect ratio.

Thanks.

 
S

Stimp

Well I want to basically resize the image to the width of the new
rectangle (i.e. 100 pixels), but then to crop this new image around the
centre with a crop height of 80 pixels (or whatever value the target
rectangle is)

The new image must be in the same aspect ratio.

I've just noticed that my example was a bit odd since the source and
destination rectangles are the same ratio (doh!)

Ok a better example would be:

Source rectangle: 363px x 251px

and the destination rectangle is: 212px x 57px
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top