Resize to exact width or height

Resize to exact width or height instead of using a ratio for both width
and height.
This commit is contained in:
Michael Delpach 2015-04-21 09:59:14 +08:00
parent d0be0cff95
commit 34bb70b277
2 changed files with 13 additions and 4 deletions

View file

@ -183,13 +183,21 @@ public static Image ResizeImageLimit(Image img, int width, int height)
double ratioX = (double)width / img.Width;
double ratioY = (double)height / img.Height;
double ratio = ratioX < ratioY ? ratioX : ratioY;
int newWidth = (int)(img.Width * ratio);
int newHeight = (int)(img.Height * ratio);
int newWidth = width;
int newHeight = height;
if (ratioX < ratioY)
newHeight = (int)(img.Height * ratioX);
else
newWidth = (int)(img.Width * ratioY);
return ResizeImage(img, newWidth, newHeight);
}
public static Image ResizeImageLimit(Image img, int maxPixels)
{
return ResizeImageLimit(img, maxPixels, maxPixels);
}
public static Image CropImage(Image img, Rectangle rect)
{
if (img != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 &&

View file

@ -37,7 +37,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
@ -49,6 +49,7 @@
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="Gma.QrCodeNet.Encoding, Version=0.4.0.0, Culture=neutral, processorArchitecture=MSIL">