added resize image
This commit is contained in:
parent
08cf132361
commit
8adee2bfd9
|
@ -40,6 +40,7 @@
|
||||||
<Compile Include="BorderCropper.cs" />
|
<Compile Include="BorderCropper.cs" />
|
||||||
<Compile Include="GetCopyImage.cs" />
|
<Compile Include="GetCopyImage.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ResizeImage.cs" />
|
||||||
<Compile Include="Resolution.cs" />
|
<Compile Include="Resolution.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
|
||||||
|
namespace Mk0.Tools.Images
|
||||||
|
{
|
||||||
|
public class Resize
|
||||||
|
{
|
||||||
|
public static Bitmap ResizeImage(Image image, int width, int height)
|
||||||
|
{
|
||||||
|
var destRect = new Rectangle(0, 0, width, height);
|
||||||
|
var destImage = new Bitmap(width, height);
|
||||||
|
|
||||||
|
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
|
||||||
|
|
||||||
|
using (var graphics = Graphics.FromImage(destImage))
|
||||||
|
{
|
||||||
|
graphics.CompositingMode = CompositingMode.SourceCopy;
|
||||||
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
|
|
||||||
|
using (var wrapMode = new ImageAttributes())
|
||||||
|
{
|
||||||
|
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||||
|
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return destImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue