Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...