tags:

views:

750

answers:

3
A: 

Given that the percentage that you are scaling by will not always yield an integral result, that is going to lead to a rounding error which will produce the border.

You are going to have to determine if rounding in any dimension will add a pixel border (you can check the rounding). If it does, then you can create a new bitmap and then copy the section of the picture over that does not include the border.

casperOne
I hadn't considered rounding. Nice!
strager
Sadly, but this is not a problem of percentage. You could try any height and width(add or subtract any number of pixels after applying percentage) but result will be the same.
horseman
+1  A: 

That will occur if your line is only 1 pixel wide in the original. When it resizes, the algorithm causes the border on right and bottom to appear "trimmed off", when in fact, what is occurring is the algorithm places a degree of importance based on pixel hue/color/saturation/placement. It deems that the interior cells take precedence and the border gets lost. Various graphic applications such as Adobe Photoshop and Corel PaintShop Pro give you various resize options [interpolation modes] to help avoid things like this. You need to change the interpolationMode to something different. I haven't used GDI+ in a while, so I forget what the available modes are. Try each of the modes to see which is most acceptable to you.

What I would likely do is this to guarantee the integrity of the border:

  • Strip the border off the original picture
  • Resize the remaining portion of the picture
  • Add a border back to the resulting picture

This way your border will remain unchanged - a single red pixel surrounding the resized image.

BenAlabaster
It's not a problem of the border- it's question how to save this one pixel from right and bottom edges. In you approach on last step I'll have border(with original size) and rest of image(already scaled). To Add border back I should scale it to the size of image and this is vicious circle :-(
horseman
+2  A: 

This is a bug in .NET graphics, and a tremendously annoying one. It is not a rounding error or an algorithm problem. You can see a variant of the same problem if you create a 100x100 bitmap and then call DrawRectangle using a 100x100 rectangle as one of the parameters: you will not see the bottom or right sides of the drawn rectangle.

MusiGenesis