Meanie Posted February 27, 2003 Posted February 27, 2003 I'm scaling a wallpaper image down into a display area of 152x114 and noticed an image's 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 i've 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. Here's my 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? Quote
*Gurus* divil Posted February 27, 2003 *Gurus* Posted February 27, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Meanie Posted February 27, 2003 Author Posted February 27, 2003 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.