Image scaling and actual image size

Meanie

Member
Joined
Jan 4, 2003
Messages
23
Im scaling a wallpaper image down into a display area of 152x114 and noticed an images resolution affects the actual scaling of the image.

For instance, an image 1024x768 with a resolution of 96x96 scales down fine, but a same sized image with a resolution of 72x72 is clipped, with only a portion of the image appearing in the display area.

My maths is a little rusty on the subject, but ive managed to factor in the resolution of an image, but the outcome results with the image now slightly smaller than the display area, resulting in grey lines appearin on the bottom and on the right of the image.

Heres my code:

Code:
            giXLen = 152
            giYLen = 114

            xImgLen = img.Width / (img.HorizontalResolution / 100)
            yImgLen = img.Height / (img.VerticalResolution / 100)

            dXratio = giXLen / xImgLen           
            dYratio = giYLen / yImgLen            

             Scale image
            G.ScaleTransform(dXratio, dYratio)

            G.DrawImage(img, pOffset)

What else am I supposed to take into account in determining the actual image size so I can find the proper scaling ratio?
 
I may be slightly off track here, but one of the overloads for Graphics.DrawImage accepts a rectangle structure which it will scale the image appropriately to fit in to. You may be able to just get away with passing it the target rectangle and it will do everything for you.
 
Moved, eh? Hehe, I posted in General because I thought I was posting a maths question :D

Anway, thank, that worked. Now I feel real silly for not realising this at first because I have been using the same sized rectangle for other parts of the code. Oh well, we learn, eh?
 
Back
Top