Skip to content

Commit

Permalink
Add referemce to System.Drawing.Common
Browse files Browse the repository at this point in the history
  • Loading branch information
liangtie committed Nov 8, 2023
1 parent cb22eba commit 9616001
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions KiBuild/Private/New-TileIconSub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,43 @@

$imageHelper = @"
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Common;
public class ImageHelper
{
public static void TilizeIcon(string sourcePath, int finalWidth, int finalHeight, string finalPath)
{
File.Copy(sourcePath,finalPath);
using (var finalImage = new Bitmap(finalWidth, finalHeight))
{
using (var source = new Bitmap(sourcePath))
{
if(source.Width > finalWidth)
{
throw new ArgumentOutOfRangeException("Source width is larger than the final width");
}
if (source.Height > finalHeight)
{
throw new ArgumentOutOfRangeException("Source height is larger than the final height");
}
using (Graphics g = Graphics.FromImage(finalImage))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(source, (finalWidth-source.Width)/2, (finalHeight-source.Height)/2, source.Width, source.Height);
}
}
finalImage.Save(finalPath, ImageFormat.Png);
}
}
}
"@

$assemblies = ("System.Drawing", "System.Drawing.Primitives", "System.Runtime")
$assemblies = ("System.Drawing", "System.Drawing.Primitives", "System.Runtime", "System.Drawing.Common")
Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $imageHelper -Language CSharp -IgnoreWarnings
function New-TileIconSub {
<#
Expand Down

0 comments on commit 9616001

Please sign in to comment.