Browse Source

Fixing rounding issue

Former-commit-id: 38e8b95badce1db2f69a3a15dfe6fa71f7c5455b
af/merge-core
James South 12 years ago
parent
commit
2dedf0b5d9
  1. 14
      src/ImageProcessor/Processors/Resize.cs
  2. 1
      src/TestWebsites/NET45/Test_Website_NET45/Images/header_1.jpg.REMOVED.git-id
  3. 5
      src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj
  4. 7
      src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml

14
src/ImageProcessor/Processors/Resize.cs

@ -252,13 +252,13 @@ namespace ImageProcessor.Processors
{ {
ratio = percentHeight; ratio = percentHeight;
destinationX = (int)((width - (sourceWidth * ratio)) / 2); destinationX = (int)((width - (sourceWidth * ratio)) / 2);
destinationWidth = (int)Math.Floor(sourceWidth * percentHeight); destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight);
} }
else else
{ {
ratio = percentWidth; ratio = percentWidth;
destinationY = (int)((height - (sourceHeight * ratio)) / 2); destinationY = (int)((height - (sourceHeight * ratio)) / 2);
destinationHeight = (int)Math.Floor(sourceHeight * percentWidth); destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth);
} }
} }
@ -285,7 +285,7 @@ namespace ImageProcessor.Processors
break; break;
} }
destinationHeight = (int)Math.Floor(sourceHeight * percentWidth); destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth);
} }
else else
{ {
@ -304,7 +304,7 @@ namespace ImageProcessor.Processors
break; break;
} }
destinationWidth = (int)Math.Floor(sourceWidth * percentHeight); destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight);
} }
} }
@ -330,13 +330,13 @@ namespace ImageProcessor.Processors
// If height or width is not passed we assume that the standard ratio is to be kept. // If height or width is not passed we assume that the standard ratio is to be kept.
if (height == 0) if (height == 0)
{ {
destinationHeight = (int)Math.Floor(sourceHeight * percentWidth); destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth);
height = destinationHeight; height = destinationHeight;
} }
if (width == 0) if (width == 0)
{ {
destinationWidth = (int)Math.Floor(sourceWidth * percentHeight); destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight);
width = destinationWidth; width = destinationWidth;
} }
@ -376,7 +376,7 @@ namespace ImageProcessor.Processors
} }
// An unwanted border appears when using InterpolationMode.HighQualityBicubic to resize the image // An unwanted border appears when using InterpolationMode.HighQualityBicubic to resize the image
// as the algorithm appears to be pulling averaging detail from surFlooring pixels beyond the edge // as the algorithm appears to be pulling averaging detail from surCeilinging pixels beyond the edge
// of the image. Using the ImageAttributes class to specify that the pixels beyond are simply mirror // of the image. Using the ImageAttributes class to specify that the pixels beyond are simply mirror
// images of the pixels within solves this problem. // images of the pixels within solves this problem.
using (ImageAttributes wrapMode = new ImageAttributes()) using (ImageAttributes wrapMode = new ImageAttributes())

1
src/TestWebsites/NET45/Test_Website_NET45/Images/header_1.jpg.REMOVED.git-id

@ -0,0 +1 @@
f956fa8105d6d9628a0413b8884ec7684e820381

5
src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj

@ -127,15 +127,16 @@
<Content Include="Images\cmyk.png" /> <Content Include="Images\cmyk.png" />
<Content Include="Images\color-vision-test.gif" /> <Content Include="Images\color-vision-test.gif" />
<Content Include="Images\Desert.jpg" /> <Content Include="Images\Desert.jpg" />
<Content Include="Images\emma.jpg" />
<Content Include="Images\fid11246.jpg" /> <Content Include="Images\fid11246.jpg" />
<Content Include="Images\fid9141.jpg" /> <Content Include="Images\fid9141.jpg" />
<Content Include="Images\header_1.jpg" />
<Content Include="Images\Hydrangeas.jpg" /> <Content Include="Images\Hydrangeas.jpg" />
<Content Include="Images\Jellyfish.jpg" /> <Content Include="Images\Jellyfish.jpg" />
<Content Include="Images\jrt.jpg" /> <Content Include="Images\jrt.jpg" />
<Content Include="Images\Koala.jpg" /> <Content Include="Images\Koala.jpg" />
<Content Include="Images\Lighthouse.jpg" /> <Content Include="Images\Lighthouse.jpg" />
<Content Include="Images\lomo.jpg" /> <Content Include="Images\lomo.jpg" />
<Content Include="Images\MSwanson - Wide Large - Rock 02.jpg" />
<Content Include="Images\negative.png" /> <Content Include="Images\negative.png" />
<Content Include="Images\negative2.png" /> <Content Include="Images\negative2.png" />
<Content Include="Images\Penguins-200.jpg" /> <Content Include="Images\Penguins-200.jpg" />
@ -145,10 +146,12 @@
<Content Include="Images\Penguins.jpg" /> <Content Include="Images\Penguins.jpg" />
<Content Include="Images\Penguins.png" /> <Content Include="Images\Penguins.png" />
<Content Include="Images\Penguins.tif" /> <Content Include="Images\Penguins.tif" />
<Content Include="Images\rocks.jpg" />
<Content Include="Images\sample1.jpg" /> <Content Include="Images\sample1.jpg" />
<Content Include="Images\srgb.jpg" /> <Content Include="Images\srgb.jpg" />
<Content Include="Images\srgb.png" /> <Content Include="Images\srgb.png" />
<Content Include="Images\text.png" /> <Content Include="Images\text.png" />
<Content Include="Images\thor.jpg" />
<Content Include="Images\Tulips.jpg" /> <Content Include="Images\Tulips.jpg" />
<Content Include="Images\udendørs-374.jpg" /> <Content Include="Images\udendørs-374.jpg" />
<Content Include="Images\udendørs.jpg" /> <Content Include="Images\udendørs.jpg" />

7
src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml

@ -209,4 +209,11 @@
</div> </div>
</div> </div>
</section> </section>
<section>
<div class="row">
<h2>Rounding</h2>
<img src="/Images/header_1.jpg?crop=0-43-683-200&width=750&height=220" />
<img src="/Images/header_1.jpg?width=750&crop=0-48-750-220" />
</div>
</section>
</article> </article>

Loading…
Cancel
Save