diff --git a/.gitignore b/.gitignore index b31955f..17ea1ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,20 @@ # This .gitignore file was automatically created by Microsoft(R) Visual Studio. ################################################################################ -/bin +/NetImageLibrary.Core/bin +/NetImageLibrary.Core/obj +/NetImageLibrary.FastFilters/bin +/NetImageLibrary.FastFilters/obj +/TestAppNet461/bin +/TestAppNet461/obj +/TestAppNet461/output/*.jpg +/TestAppNet461/output/*.png +/TestAppNetCore/bin +/TestAppNetCore/obj +/TestAppNetCore/output/*.jpg +/TestAppNetCore/output/*.png /.nuget -/FastFilters/bin -/FastFilters/obj -/obj +/.vs *.bat *.suo *.user diff --git a/FastFilters/ImageLibrary.FastFilters.csproj b/FastFilters/ImageLibrary.FastFilters.csproj deleted file mode 100644 index 02ffd80..0000000 --- a/FastFilters/ImageLibrary.FastFilters.csproj +++ /dev/null @@ -1,89 +0,0 @@ - - - - - Debug - AnyCPU - {8F14659B-DF8B-45ED-A5CB-72F09DC44DF1} - Library - Properties - Kaliko.ImageLibrary.FastFilters - Kaliko.ImageLibrary.FastFilters - v4.0 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true - - - pdbonly - true - TRACE - prompt - 4 - true - ..\..\.build\filters\net40\Kaliko.ImageLibrary.FastFilters.XML - ..\..\.build\filters\net40\ - v4.0 - - - pdbonly - true - TRACE - prompt - 4 - true - ..\..\.build\filters\net45\Kaliko.ImageLibrary.FastFilters.XML - ..\..\.build\filters\net45\ - v4.5 - - - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - {073c7180-35e8-442a-9334-aa3f529c0985} - ImageLibrary - - - - - \ No newline at end of file diff --git a/FastFilters/Properties/AssemblyInfo.cs b/FastFilters/Properties/AssemblyInfo.cs deleted file mode 100644 index bc8d0f3..0000000 --- a/FastFilters/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Fast filters for Kaliko Image Library")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Kaliko")] -[assembly: AssemblyProduct("ImageLibrary.FastFilters")] -[assembly: AssemblyCopyright("Copyright © Fredrik Schultz and Contributors")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2e583ffe-2595-4888-8116-a6c92e15f3d8")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -//[assembly: AssemblyVersion("1.0.0.0")] -//[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ImageLibrary.csproj b/ImageLibrary.csproj deleted file mode 100644 index a84d16b..0000000 --- a/ImageLibrary.csproj +++ /dev/null @@ -1,148 +0,0 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {073C7180-35E8-442A-9334-AA3F529C0985} - Library - Properties - Kaliko.ImageLibrary - Kaliko.ImageLibrary - - - v2.0 - - - - - 2.0 - - - true - full - false - bin\Debug\ - TRACE;DEBUG - prompt - 4 - true - bin\Debug\Kaliko.ImageLibrary.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - bin\Release\Kaliko.ImageLibrary.XML - - - pdbonly - true - TRACE - prompt - 4 - false - ..\.build\net20\Kaliko.ImageLibrary.XML - ..\.build\net20\ - v2.0 - - - pdbonly - true - TRACE - prompt - 4 - false - ..\.build\net30\Kaliko.ImageLibrary.XML - ..\.build\net30\ - v3.0 - - - pdbonly - true - TRACE - prompt - 4 - false - ..\.build\net35\Kaliko.ImageLibrary.XML - ..\.build\net35\ - v3.5 - - - pdbonly - true - TRACE - prompt - 4 - false - ..\.build\net40\Kaliko.ImageLibrary.XML - ..\.build\net40\ - v4.0 - - - pdbonly - true - TRACE - prompt - 4 - false - ..\.build\net45\Kaliko.ImageLibrary.XML - ..\.build\net45\ - v4.5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ImageLibrary.sln b/ImageLibrary.sln index 4c9d277..2ec677e 100644 --- a/ImageLibrary.sln +++ b/ImageLibrary.sln @@ -1,20 +1,21 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28917.181 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageLibrary", "ImageLibrary.csproj", "{073C7180-35E8-442A-9334-AA3F529C0985}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{4381B75F-8E8B-4F82-AABC-A16AD72D201A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetImageLibrary.Core", "NetImageLibrary.Core\NetImageLibrary.Core.csproj", "{073C7180-35E8-442A-9334-AA3F529C0985}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6B47240A-4B86-4A32-8618-26626B0928CF}" ProjectSection(SolutionItems) = preProject README.md = README.md ReleaseNotes.md = ReleaseNotes.md - Properties\SolutionInfo.cs = Properties\SolutionInfo.cs EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageLibrary.FastFilters", "FastFilters\ImageLibrary.FastFilters.csproj", "{8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetImageLibrary.FastFilters", "NetImageLibrary.FastFilters\NetImageLibrary.FastFilters.csproj", "{8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppNetCore", "TestAppNetCore\TestAppNetCore.csproj", "{50CF71F8-7EA1-45E0-999D-0E7D03DF0445}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppNet461", "TestAppNet461\TestAppNet461.csproj", "{1D6039A4-5D21-4454-BD74-59A395019401}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -26,16 +27,23 @@ Global {073C7180-35E8-442A-9334-AA3F529C0985}.Debug|Any CPU.Build.0 = Debug|Any CPU {073C7180-35E8-442A-9334-AA3F529C0985}.Release|Any CPU.ActiveCfg = Release|Any CPU {073C7180-35E8-442A-9334-AA3F529C0985}.Release|Any CPU.Build.0 = Release|Any CPU - {4381B75F-8E8B-4F82-AABC-A16AD72D201A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4381B75F-8E8B-4F82-AABC-A16AD72D201A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4381B75F-8E8B-4F82-AABC-A16AD72D201A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4381B75F-8E8B-4F82-AABC-A16AD72D201A}.Release|Any CPU.Build.0 = Release|Any CPU {8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU {8F14659B-DF8B-45ED-A5CB-72F09DC44DF1}.Release|Any CPU.Build.0 = Release|Any CPU + {50CF71F8-7EA1-45E0-999D-0E7D03DF0445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50CF71F8-7EA1-45E0-999D-0E7D03DF0445}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50CF71F8-7EA1-45E0-999D-0E7D03DF0445}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50CF71F8-7EA1-45E0-999D-0E7D03DF0445}.Release|Any CPU.Build.0 = Release|Any CPU + {1D6039A4-5D21-4454-BD74-59A395019401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D6039A4-5D21-4454-BD74-59A395019401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D6039A4-5D21-4454-BD74-59A395019401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D6039A4-5D21-4454-BD74-59A395019401}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {147E054F-DD35-49F0-95DD-5360C9C8DB7C} + EndGlobalSection EndGlobal diff --git a/ColorHandler.cs b/NetImageLibrary.Core/ColorHandler.cs similarity index 100% rename from ColorHandler.cs rename to NetImageLibrary.Core/ColorHandler.cs diff --git a/ColorSpace/CIELab.cs b/NetImageLibrary.Core/ColorSpace/CIELab.cs similarity index 94% rename from ColorSpace/CIELab.cs rename to NetImageLibrary.Core/ColorSpace/CIELab.cs index 862cf2f..cfecd3f 100644 --- a/ColorSpace/CIELab.cs +++ b/NetImageLibrary.Core/ColorSpace/CIELab.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/CIEXYZ.cs b/NetImageLibrary.Core/ColorSpace/CIEXYZ.cs similarity index 95% rename from ColorSpace/CIEXYZ.cs rename to NetImageLibrary.Core/ColorSpace/CIEXYZ.cs index a805d2c..db8c8a9 100644 --- a/ColorSpace/CIEXYZ.cs +++ b/NetImageLibrary.Core/ColorSpace/CIEXYZ.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/CMYK.cs b/NetImageLibrary.Core/ColorSpace/CMYK.cs similarity index 95% rename from ColorSpace/CMYK.cs rename to NetImageLibrary.Core/ColorSpace/CMYK.cs index 8f5baca..3599e61 100644 --- a/ColorSpace/CMYK.cs +++ b/NetImageLibrary.Core/ColorSpace/CMYK.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/ColorSpaceHelper.cs b/NetImageLibrary.Core/ColorSpace/ColorSpaceHelper.cs similarity index 94% rename from ColorSpace/ColorSpaceHelper.cs rename to NetImageLibrary.Core/ColorSpace/ColorSpaceHelper.cs index cba4f82..8acfd6d 100644 --- a/ColorSpace/ColorSpaceHelper.cs +++ b/NetImageLibrary.Core/ColorSpace/ColorSpaceHelper.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; using System.Drawing; @@ -49,17 +50,17 @@ public static double GetColorDistance(double[] color1, double[] color2) { /// /// First color. /// Second color. - public static double GetColorDistance(Color c1, Color c2) { + public static double GetColorDistance(Color color1, Color color2) { double[] rgb1 = new double[] { - (double)c1.R/255.0, - (double)c1.G/255.0, - (double)c1.B/255.0 + (double)color1.R/255.0, + (double)color1.G/255.0, + (double)color1.B/255.0 }; double[] rgb2 = new double[] { - (double)c2.R/255.0, - (double)c2.G/255.0, - (double)c2.B/255.0 + (double)color2.R/255.0, + (double)color2.G/255.0, + (double)color2.B/255.0 }; return GetColorDistance(rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2]); @@ -190,7 +191,7 @@ public static string RGBToHex(int r, int g, int b) { /// /// Converts a RGB color format to an hexadecimal color. /// - /// The color to convert. + /// The color to convert. public static string RGBToHex(Color c) { return RGBToHex(c.R, c.G, c.B); } @@ -202,7 +203,7 @@ public static string RGBToHex(Color c) { /// /// Converts HSB to RGB. /// - /// The HSB structure to convert. + /// The HSB structure to convert. public static RGB HSBtoRGB(HSB hsb) { double r = 0; double g = 0; @@ -268,9 +269,9 @@ public static RGB HSBtoRGB(HSB hsb) { /// /// Converts HSB to RGB. /// - /// Hue value. - /// Saturation value. - /// Brigthness value. + /// Hue value. + /// Saturation value. + /// Brigthness value. public static RGB HSBtoRGB(double h, double s, double b) { return HSBtoRGB(new HSB(h, s, b)); } @@ -279,7 +280,7 @@ public static RGB HSBtoRGB(double h, double s, double b) { /// /// Converts HSB to Color. /// - /// the HSB structure to convert. + /// the HSB structure to convert. public static Color HSBtoColor(HSB hsb) { RGB rgb = HSBtoRGB(hsb); @@ -410,7 +411,9 @@ public static RGB HSLtoRGB(HSL hsl) { /// /// Converts HSL to .net Color. /// - /// The HSL structure to convert. + /// + /// + /// public static Color HSLtoColor(double h, double s, double l) { RGB rgb = HSLtoRGB(h, s, l); diff --git a/ColorSpace/HSB.cs b/NetImageLibrary.Core/ColorSpace/HSB.cs similarity index 95% rename from ColorSpace/HSB.cs rename to NetImageLibrary.Core/ColorSpace/HSB.cs index 86041ea..c055220 100644 --- a/ColorSpace/HSB.cs +++ b/NetImageLibrary.Core/ColorSpace/HSB.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/HSL.cs b/NetImageLibrary.Core/ColorSpace/HSL.cs similarity index 95% rename from ColorSpace/HSL.cs rename to NetImageLibrary.Core/ColorSpace/HSL.cs index 192655d..8f69c40 100644 --- a/ColorSpace/HSL.cs +++ b/NetImageLibrary.Core/ColorSpace/HSL.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/RGB.cs b/NetImageLibrary.Core/ColorSpace/RGB.cs similarity index 95% rename from ColorSpace/RGB.cs rename to NetImageLibrary.Core/ColorSpace/RGB.cs index 86a9005..14864e5 100644 --- a/ColorSpace/RGB.cs +++ b/NetImageLibrary.Core/ColorSpace/RGB.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/ColorSpace/YUV.cs b/NetImageLibrary.Core/ColorSpace/YUV.cs similarity index 95% rename from ColorSpace/YUV.cs rename to NetImageLibrary.Core/ColorSpace/YUV.cs index 2d4f558..996078a 100644 --- a/ColorSpace/YUV.cs +++ b/NetImageLibrary.Core/ColorSpace/YUV.cs @@ -2,6 +2,7 @@ // Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL) #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.ColorSpace { using System; diff --git a/Filters/BrightnessFilter.cs b/NetImageLibrary.Core/Filters/BrightnessFilter.cs similarity index 96% rename from Filters/BrightnessFilter.cs rename to NetImageLibrary.Core/Filters/BrightnessFilter.cs index 06fef6b..6ec972e 100644 --- a/Filters/BrightnessFilter.cs +++ b/NetImageLibrary.Core/Filters/BrightnessFilter.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { using System; diff --git a/Filters/ChromaKeyFilter.cs b/NetImageLibrary.Core/Filters/ChromaKeyFilter.cs similarity index 94% rename from Filters/ChromaKeyFilter.cs rename to NetImageLibrary.Core/Filters/ChromaKeyFilter.cs index 53c088d..b12f33c 100644 --- a/Filters/ChromaKeyFilter.cs +++ b/NetImageLibrary.Core/Filters/ChromaKeyFilter.cs @@ -19,11 +19,15 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { using System; using System.Drawing; using ColorSpace; + /// + /// Chrome key filter + /// public class ChromaKeyFilter : IFilter { public float ToleranceHue { get; set; } diff --git a/Filters/ContrastFilter.cs b/NetImageLibrary.Core/Filters/ContrastFilter.cs similarity index 100% rename from Filters/ContrastFilter.cs rename to NetImageLibrary.Core/Filters/ContrastFilter.cs diff --git a/Filters/ConvolveFilter.cs b/NetImageLibrary.Core/Filters/ConvolveFilter.cs similarity index 97% rename from Filters/ConvolveFilter.cs rename to NetImageLibrary.Core/Filters/ConvolveFilter.cs index 13cab78..a8c77d8 100644 --- a/Filters/ConvolveFilter.cs +++ b/NetImageLibrary.Core/Filters/ConvolveFilter.cs @@ -19,6 +19,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { using System; diff --git a/Filters/DesaturationFilter.cs b/NetImageLibrary.Core/Filters/DesaturationFilter.cs similarity index 92% rename from Filters/DesaturationFilter.cs rename to NetImageLibrary.Core/Filters/DesaturationFilter.cs index 2decfca..8cbf54d 100644 --- a/Filters/DesaturationFilter.cs +++ b/NetImageLibrary.Core/Filters/DesaturationFilter.cs @@ -25,7 +25,11 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { + /// + /// Desaturation filter + /// public class DesaturationFilter : IFilter { public void Run(KalikoImage image) { diff --git a/Filters/GaussianBlurFilter.cs b/NetImageLibrary.Core/Filters/GaussianBlurFilter.cs similarity index 100% rename from Filters/GaussianBlurFilter.cs rename to NetImageLibrary.Core/Filters/GaussianBlurFilter.cs diff --git a/Filters/IFilter.cs b/NetImageLibrary.Core/Filters/IFilter.cs similarity index 95% rename from Filters/IFilter.cs rename to NetImageLibrary.Core/Filters/IFilter.cs index 1584839..4e2afdf 100644 --- a/Filters/IFilter.cs +++ b/NetImageLibrary.Core/Filters/IFilter.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { public interface IFilter { diff --git a/Filters/InvertFilter.cs b/NetImageLibrary.Core/Filters/InvertFilter.cs similarity index 92% rename from Filters/InvertFilter.cs rename to NetImageLibrary.Core/Filters/InvertFilter.cs index 4455b19..2f018e2 100644 --- a/Filters/InvertFilter.cs +++ b/NetImageLibrary.Core/Filters/InvertFilter.cs @@ -25,7 +25,11 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Filters { + /// + /// Color invert filter + /// public class InvertFilter : IFilter { public void Run(KalikoImage image) { InvertImage(image); diff --git a/Filters/Kernel.cs b/NetImageLibrary.Core/Filters/Kernel.cs similarity index 86% rename from Filters/Kernel.cs rename to NetImageLibrary.Core/Filters/Kernel.cs index 15e17f6..bca4114 100644 --- a/Filters/Kernel.cs +++ b/NetImageLibrary.Core/Filters/Kernel.cs @@ -1,4 +1,5 @@ -namespace Kaliko.ImageLibrary.Filters { +#pragma warning disable 1591 +namespace Kaliko.ImageLibrary.Filters { using System; public class Kernel diff --git a/Filters/UnsharpMaskFilter.cs b/NetImageLibrary.Core/Filters/UnsharpMaskFilter.cs similarity index 100% rename from Filters/UnsharpMaskFilter.cs rename to NetImageLibrary.Core/Filters/UnsharpMaskFilter.cs diff --git a/ImageOutput.cs b/NetImageLibrary.Core/ImageOutput.cs similarity index 93% rename from ImageOutput.cs rename to NetImageLibrary.Core/ImageOutput.cs index a6d2527..7c6735e 100644 --- a/ImageOutput.cs +++ b/NetImageLibrary.Core/ImageOutput.cs @@ -30,7 +30,9 @@ namespace Kaliko.ImageLibrary { using System.Drawing; using System.Drawing.Imaging; using System.IO; +#if NET46 using System.Web; +#endif internal class ImageOutput { private static ImageCodecInfo GetEncoderInfo(String mimeType) { @@ -45,6 +47,10 @@ private static ImageCodecInfo GetEncoderInfo(String mimeType) { return null; } +#if NET46 + // httpresponse doesn't exist in netStandard, at least not in the same way. Can't + // get the outputstream, even if you use the extensions & abstractons packages. + internal static Stream PrepareImageStream(string fileName, string mime) { HttpResponse stream = HttpContext.Current.Response; stream.Clear(); @@ -54,6 +60,7 @@ internal static Stream PrepareImageStream(string fileName, string mime) { stream.AddHeader("Content-Disposition", "inline;filename=" + fileName); return stream.OutputStream; } +#endif internal static void SaveStream(KalikoImage image, Stream stream, long quality, string imageFormat, bool saveResolution) { var encoderParameters = GetEncoderParameters(quality); diff --git a/KalikoImage.cs b/NetImageLibrary.Core/KalikoImage.cs similarity index 95% rename from KalikoImage.cs rename to NetImageLibrary.Core/KalikoImage.cs index 9258ee5..1ad3823 100644 --- a/KalikoImage.cs +++ b/NetImageLibrary.Core/KalikoImage.cs @@ -142,7 +142,6 @@ public void Destroy() { if (Image != null) Image.Dispose(); } - #endregion @@ -654,7 +653,9 @@ public void Crop(int x, int y, int width, int height) { /// Resizes the image without any consideration of the current - /// ratio. If you wish to make a ratio locked resize use Scale Method instead. + /// ratio. If you wish to make a ratio locked resize use Scale Method + /// Scale + /// instead. /// /// /// @@ -679,12 +680,12 @@ public void Resize(int width, int height) { Image = image.Image; } - #endregion - #region Functions for image saving and streaming +#if NET46 + /// Save image to the response stream in JPG-format. Ideal for sending realtime generated images to the web client requesting it. /// /// @@ -694,7 +695,6 @@ public void StreamJpg(long quality, string fileName) { SaveJpg(imageStream, quality); } - /// /// Save image to the response stream in PNG-format. Ideal for sending realtime generated images to the web client requesting it. /// @@ -713,6 +713,20 @@ public void StreamGif(string fileName) { SaveGif(imageStream); } +#endif + +#if NETCOREAPP || NETSTANDARD +#pragma warning disable 1591 + [Obsolete("Use SaveJpg passing your stream instead")] + public void StreamJpg(long quality, string fileName) { throw new NotImplementedException(); } + + [Obsolete("Use SavePng passing your stream instead")] + public void StreamPng(string fileName) { throw new NotImplementedException(); } + + [Obsolete("Use SaveGif passing your stream instead")] + public void StreamGif(string fileName) { throw new NotImplementedException(); } +#pragma warning restore 1591 +#endif /// Save image to stream in JPG-format /// Stream to save the image to @@ -919,10 +933,10 @@ public void SaveImage(string fileName, ImageFormat format) { } - #endregion +#endregion - #region Functions for filters and bitmap manipulation +#region Functions for filters and bitmap manipulation private byte[] _byteArray; private bool _disposed; @@ -994,10 +1008,10 @@ public void ApplyFilter(Filters.IFilter filter) { filter.Run(this); } - #endregion +#endregion - #region Functions for rotation +#region Functions for rotation /// /// Rotates, flips, or rotates and flips the image @@ -1008,7 +1022,7 @@ public void RotateFlip(RotateFlipType rotateFlipType) { _g = Graphics.FromImage(Image); } - #endregion +#endregion /// Int array matching PixelFormat.Format32bppArgb (bgrA in real life) public int[] IntArray { @@ -1051,6 +1065,9 @@ protected virtual void Dispose(bool disposing) { _disposed = true; } + /// + /// Dispose + /// ~KalikoImage() { Dispose(false); } @@ -1062,7 +1079,7 @@ public void Dispose() { } - #region Deprecated methods only kept for legacy +#region Deprecated methods only kept for legacy /// /// @@ -1092,6 +1109,6 @@ public KalikoImage GetThumbnailImage(int width, int height, ThumbnailMethod meth return Scale(scaleEngine); } - #endregion +#endregion } } \ No newline at end of file diff --git a/NetImageLibrary.Core/NetImageLibrary.Core.csproj b/NetImageLibrary.Core/NetImageLibrary.Core.csproj new file mode 100644 index 0000000..dc9cb7e --- /dev/null +++ b/NetImageLibrary.Core/NetImageLibrary.Core.csproj @@ -0,0 +1,79 @@ + + + + netcoreapp2.0;netstandard2.0;net40;net461;net5.0 + 4.0-beta1 + true + Kaliko.ImageLibrary + true + ImageLibrary + https://kaliko.com/image-library/ + https://kaliko.com/external/imagelibrary-logo.png + MIT + https://github.com/fschultz/NetImageLibrary + Fredrik Schultz / Kaliko + Fredrik Schultz and Contributors + Library to help with image handling such as resizing, cropping, applying filters (brightess, contrast, unsharpen mask, chroma key etc), watermarking, thumbnail creation, opening/saving files or streams and more. + .NET Image Library + image resize crop thumbnail filters unsharpen chromakey + + * Migrated projects to be compatible with .NET 4.x, .NET 5.x and Core + .\NetImageLibrary.Core.xml + + + + + + + + + + + + + + + NETSTANDARD;NETSTANDARD2_0 + + + + + NETCOREAPP;NETCOREAPP2_0 + + + + + + + + NETCOREAPP;NETCOREAPP5_0 + + + + + NET46;NETFULL + + + + + + + + + + + + + + NET46;NETFULL + + + + + + + + + + + diff --git a/NetImageLibrary.Core/NetImageLibrary.Core.xml b/NetImageLibrary.Core/NetImageLibrary.Core.xml new file mode 100644 index 0000000..9cd02b3 --- /dev/null +++ b/NetImageLibrary.Core/NetImageLibrary.Core.xml @@ -0,0 +1,1488 @@ + + + + NetImageLibrary.Core + + + + + Class to handle color specific code. + + + + + + + Parse a web color type of string (for example "#FF0000") into a System.Drawing.Color object. + + Color in string format (i e "#FFFFFF") + Color + + + + Structure to define CIE L*a*b*. + + + + + Gets an empty CIELab structure. + + + + + Gets or sets L component. + + + + + Gets or sets a component. + + + + + Gets or sets a component. + + + + + Structure to define CIE XYZ. + + + + + Gets an empty CIEXYZ structure. + + + + + Gets the CIE D65 (white) structure. + + + + + Gets or sets X component. + + + + + Gets or sets Y component. + + + + + Gets or sets Z component. + + + + + Structure to define CMYK. + + + + + Gets an empty CMYK structure; + + + + + Creates an instance of a CMYK structure. + + + + + Provides methods to convert from a color space to an other. + + + + + Gets the "distance" between two colors. + RGB colors must be normalized (eg. values in [0.0, 1.0]). + + First color red component. + First color green component. + First color blue component. + Second color red component. + Second color green component. + Second color blue component. + + + + Gets the "distance" between two colors. + RGB colors must be normalized (eg. values in [0.0, 1.0]). + + First color [r,g,b] + Second color [r,g,b] + + + + Gets the "distance" between two colors. + + First color. + Second color. + + + + Gets visible colors (color wheel). + + + The alpha value used for each colors. + + + + + Gets visible spectrum colors. + + The alpha value used for each colors. + + + + Gets visible spectrum colors. + + + + + Gets the int equivalent for a hexadecimal value. + + + + + Converts a Hex color to a .net Color. + + The desired hexadecimal color to convert. + + + + Converts a RGB color format to an hexadecimal color. + + The Red value. + The Green value. + The Blue value. + + + + Converts a RGB color format to an hexadecimal color. + + The color to convert. + + + + Converts HSB to RGB. + + The HSB structure to convert. + + + + Converts HSB to RGB. + + Hue value. + Saturation value. + Brigthness value. + + + + Converts HSB to Color. + + the HSB structure to convert. + + + + Converts HSB to a .net Color. + + Hue value (must be between 0 and 360). + Saturation value (must be between 0 and 1). + Brightness value (must be between 0 and 1). + + + + Converts HSB to Color. + + Hue value. + Saturation value. + Brightness value. + + + + Converts HSB to HSL. + + + + + Converts HSB to CMYK. + + + + + Converts HSB to CMYK. + + + + + Converts HSL to RGB. + + Hue, must be in [0, 360]. + Saturation, must be in [0, 1]. + Luminance, must be in [0, 1]. + + + + Converts HSL to RGB. + + The HSL structure to convert. + + + + Converts HSL to .net Color. + + + + + + + + Converts HSL to .net Color. + + The HSL structure to convert. + + + + Converts HSL to HSB. + + + + + Converts HSL to CMYK. + + + + + Converts HSL to YUV. + + + + + Converts RGB to HSL. + + Red value, must be in [0,255]. + Green value, must be in [0,255]. + Blue value, must be in [0,255]. + + + + Converts RGB to HSL. + + + + + Converts Color to HSL. + + + + + Converts RGB to HSB. + + + + + Converts RGB to HSB. + + + + + Converts RGB to HSB. + + + + + Converts RGB to CMYK + + Red vaue must be in [0, 255]. + Green vaue must be in [0, 255]. + Blue vaue must be in [0, 255]. + + + + Converts RGB to CMYK + + + + + Converts RGB to CMYK + + + + + Converts RGB to YUV. + + red must be in [0, 255]. + green must be in [0, 255]. + blue must be in [0, 255]. + + + + Converts RGB to YUV. + + + + + Converts RGB to YUV. + + + + + Converts RGB to CIE XYZ (CIE 1931 color space) + + Red must be in [0, 255]. + Green must be in [0, 255]. + Blue must be in [0, 255]. + + + + Converts RGB to CIEXYZ. + + + + + Converts RGB to CIEXYZ. + + + + + Converts RGB to CIELab. + + + + + Converts RGB to CIELab. + + + + + Converts RGB to CIELab. + + + + + Converts CMYK to RGB. + + Cyan value (must be between 0 and 1). + Magenta value (must be between 0 and 1). + Yellow value (must be between 0 and 1). + Black value (must be between 0 and 1). + + + + Converts CMYK to RGB. + + Cyan value (must be between 0 and 1). + Magenta value (must be between 0 and 1). + Yellow value (must be between 0 and 1). + Black value (must be between 0 and 1). + + + + Converts CMYK to RGB. + + + + + + Converts CMYK to RGB. + + Cyan value (must be between 0 and 1). + Magenta value (must be between 0 and 1). + Yellow value (must be between 0 and 1). + Black value (must be between 0 and 1). + + + + Converts CMYK to RGB. + + + + + + Converts CMYK to HSL. + + + + + Converts CMYK to HSB. + + + + + Converts CMYK to YUV. + + + + + Converts YUV to RGB. + + Y must be in [0, 1]. + U must be in [-0.436, +0.436]. + V must be in [-0.615, +0.615]. + + + + Converts YUV to RGB. + + + + + Converts YUV to a .net Color. + + Y must be in [0, 1]. + U must be in [-0.436, +0.436]. + V must be in [-0.615, +0.615]. + + + + Converts YUV to a .net Color. + + + + + Converts YUV to HSL. + + Y must be in [0, 1]. + U must be in [-0.436, +0.436]. + V must be in [-0.615, +0.615]. + + + + Converts YUV to HSB. + + Y must be in [0, 1]. + U must be in [-0.436, +0.436]. + V must be in [-0.615, +0.615]. + + + + Converts YUV to CMYK. + + Y must be in [0, 1]. + U must be in [-0.436, +0.436]. + V must be in [-0.615, +0.615]. + + + + Converts CIEXYZ to RGB structure. + + + + + Converts CIEXYZ to RGB structure. + + + + + XYZ to L*a*b* transformation function. + + + + + + + Converts CIEXYZ to CIELab structure. + + + + + Converts CIEXYZ to CIELab structure. + + + + + Converts CIELab to CIEXYZ. + + + + + Converts CIELab to CIEXYZ. + + + + + Converts CIELab to RGB. + + + + + Converts CIELab to RGB. + + + + + Structure to define HSB. + + + + + Gets an empty HSB structure; + + + + + Gets or sets the hue component. + + + + + Gets or sets saturation component. + + + + + Gets or sets the brightness component. + + + + + Creates an instance of a HSB structure. + + Hue value. + Saturation value. + Brightness value. + + + + Structure to define HSL. + + + + + Gets an empty HSL structure; + + + + + Gets or sets the hue component. + + + + + Gets or sets saturation component. + + + + + Gets or sets the luminance component. + + + + + Creates an instance of a HSL structure. + + Hue value. + Saturation value. + Lightness value. + + + + Structure to define RGB. + + + + + Gets an empty RGB structure; + + + + + Structure to define YUV. + + + + + Gets an empty YUV structure. + + + + + Creates an instance of a YUV structure. + + + + Simple filter for adjusting brightness in images. + + + The amount of change to be applied to the brightness. Entered as either a positive - to make it brighter - or negative - to make it darker - value (zero + means no change). + + + Execute the filter. + + + + Chrome key filter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Treat pixels off the edge as zero. + + + + + Clamp pixels off the edge to the nearest edge. + + + + + Wrap pixels off the edge to the opposite edge. + + + + + Construct a filter with a null kernel. This is only useful if you're going to change the kernel later on. + + + + + Construct a filter with the given 3x3 kernel. + + + + + + Construct a filter with the given kernel. + + The number of rows in the kernel. + The number of columns in the kernel. + An array of rows*cols floats containing the kernel. + + + + Construct a filter with the given 3x3 kernel. + + + + + + + + + + + + + + + + + + + + + Convolve a block of pixels. + + + + + + + + + + + Convolve a block of pixels + + + + + + + + + + + + Convolve with a 2D kernel. + + + + + + + + + + + + Convolve with a kernel consisting of one row. + + + + + + + + + + + + Convolve with a kernel consisting of one column. + + + + + + + + + + + + + + + + + + + Clamp a value to the range 0..255 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Desaturation filter + + + + + + + + + + + + + + + + + + + + + The radius of the kernel, and hence the amount of blur. The bigger the radius, the longer this filter will take. + + + + + + + + + + + Blur and transpose a block of ARGB pixels. + + + + + + + + + + + + + + Make a Gaussian blur kernel. + + the blur radius + the kernel + + + + Color invert filter + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create a KalikoImage from a System.Drawing.Image. + + + + Create a KalikoImage with a defined width and height. + + + + + // Creating a new transparent image + var image = new KalikoImage(640, 480); + + + + Create a KalikoImage with a defined width and height. + + + + Create a KalikoImage with a defined width, height and background color. + + + + + Create a KalikoImage with a defined width, height and background color. + + + + + + // Creating a white image + var image = new KalikoImage(640, 480, Color.White); + + + + Create a KalikoImage by loading an image from either disk or web URL. + + + + // Open a local image: + KalikoImage image = new KalikoImage("c:\\images\\test.jpg"); + + // Load an image from the web: + KalikoImage image = new KalikoImage("http://yourdomain.com/test.jpg"); + + + + Create a KalikoImage from a stream. + + + + + + + + + Color used for background. + + + Color used for graphical operations such as writing text on image. + + + Rendering mode for text operations. + + + Horizontal resolution of image (DPI) + + + Vertical resolution of image (DPI) + + + Image width. + + + Image height. + + + Size of the image + + + + Check if the current image has an indexed palette. + + + + Returns true if image has portrait ratio (higher than wide). + + + Returns true if image has landscape ratio (wider than high). + + + Returns true if image has a 1:1 ratio (same width and height). + + + Width/height ratio of image. + + + + Create a new image as a clone. + + + + + + Get the current instance as Bitmap + + + + + + Set resolution + + + + + + + Set resolution to original values + + + + Set the font that will be used for text operations. + + + + + + Write text to image using the font assigned using SetFont Method. + Text that will be written on image + Left-most position of the text + Top-most position of the text + + + + // Write Hello World on image with semi transparent white + var image = new KalikoImage(@"C:\Img\MyImage.jpg"); + + // Load the font, relative path from the application path + image.SetFont("84_rock.ttf", 120, FontStyle.Regular); + image.Color = Color.FromArgb(64, Color.White); + image.WriteText("Hello World!", 0, 0); + + + + Write text to image using the font assigned using SetFont Method rotated in the defined angle. + Text that will be written on image + Left-most position of the text + Top-most position of the text + Angle to rotate the text to + + + + // Write Hello World on image with semi transparent white + var image = new KalikoImage(@"C:\Img\MyImage.jpg"); + + // Load the font, relative path from the application path + image.SetFont("84_rock.ttf", 120, FontStyle.Regular); + image.Color = Color.FromArgb(64, Color.White); + image.WriteText("Hello World!", 100, 100, 45); + + + + Write text to image + + + + + Load an image from local disk + + File path + + + + Load an image from a stream object (MemoryStream, Stream etc) + + Pointer to stream + + + + Load an image from an URL + + + + + + Check if image has an indexed palette and if so convert to truecolor + + + + Clear the image and set background image to the specified color. + + + + Makes a gradient fill top to bottom from one color to another. + + + + + Makes a gradient fill from point 1 to point 2 from one color to another. + + + + + + + Scale the image using a defined scaling engine which can be CropScaling Class will crop the image so that the final result always + has the given dimension, FitScaling Class will ensure that the complete image is visible inside the given + dimension or PadScaling Class that will pad the image so that it cover the given dimension. + Scale engine to use + + + + + + + Scale the image using a defined scaling engine which can be CropScaling Class will crop the image so that the final result always + has the given dimension, FitScaling Class will ensure that the complete image is visible inside the given + dimension or PadScaling Class that will pad the image so that it cover the given dimension. + Scale engine to use + Prevent upscaling + + + + + + + Will load an image and place it on the destination image at top left corner. + + + + // Load image and place on top, left of our image + image.BlitImage(@"C:\Img\Stamp.png"); + + + + Will load an image and place it on the destination image at the defined coordinates. + + + + + + // Load image and place 10 pixels from the left and 20 pixels from the top + image.BlitImage(@"C:\Img\Stamp.png", 10, 20); + + + + Will take the source image and place it on the destination image at top left corner. + + + + // Place the source image on top, left of our image + var sourceImage = new KalikoImage(@"C:\Img\Stamp.png"); + image.BlitImage(sourceImage); + + + + Will take the source image and place it on the destination image at the defined coordinates. + + + + + + // Place the source image 10 pixels from the left and 20 pixels from the top + var sourceImage = new KalikoImage(@"C:\Img\Stamp.png"); + image.BlitImage(sourceImage, 10, 20); + + + + Will take the source image and place it on the destination image at top left corner. + + + + Will take the source image and place it on the destination image at the defined coordinates. + + + + + + Loads the defined image and use it as a pattern to fill the image (will be tiled if the destination image is larger than the source image). + + + + // Repeat the above, but in a just one additional call + var image = new KalikoImage(640, 480); + image.BlitFill(@"C:\Img\Checkered.png"); + + + + Uses the defined image as a pattern to fill the image (will be tiled if the destination image is larger than the source image).. + + + + // Create a new image and fill the source image all over + var image = new KalikoImage(640, 480); + var patternImage = new KalikoImage(@"C:\Img\Checkered.png"); + image.BlitFill(patternImage); + + + + Uses the defined image as a pattern to fill the image (will be tiled if the destination image is larger than the source image).. + + + + Crop the image into the given dimensions. + + + + + + + Resizes the image without any consideration of the current + ratio. If you wish to make a ratio locked resize use Scale Method + Scale + instead. + + + + + + Save image to stream in JPG-format + Stream to save the image to + Compression quality setting (0-100) + Save original/user-defined resolution + + + // Save image to stream in jpg format with quality setting 90 + MemoryStream memoryStream = new MemoryStream(); + image.SaveJpg(memoryStream, 90, true); + + + + Save image to stream in JPG-format + Stream to save the image to + Compression quality setting (0-100) + + + // Save image to stream in jpg format with quality setting 90 + MemoryStream memoryStream = new MemoryStream(); + image.SaveJpg(memoryStream, 90); + + + + Save image to file in JPG-format. + Name of the file + Compression quality setting (0-100) + Save original/user-defined resolution + + + // Save image to file system in jpg format with quality setting 90 + image.SaveJpg(@"C:\MyImages\Output.jpg", 90, true); + + + + Save image to file in JPG-format. + Name of the file + Compression quality setting (0-100) + + + // Save image to file system in jpg format with quality setting 90 + image.SaveJpg(@"C:\MyImages\Output.jpg", 90); + + + + + + + + + + + + + + + + + + Save image to stream in PNG-format + + Save original/user-defined resolution + + + Save image to stream in PNG-format + + + + Save image to file in PNG-format. + + Save original/user-defined resolution + + + Save image to file in PNG-format. + + + + + + + + + + Save image to file in GIF-format. + + + + + Save image to file in BMP-format + + + Save original/user-defined resolution + + + + Save image to file in BMP-format + + + + + Save image to file in BMP-format. + + Save original/user-defined resolution + + + Save image to file in BMP-format. + + + + Save image to stream in BMP-format. + + + Save original/user-defined resolution + + + Save image to stream in BMP-format. + + + + + Generic method that will save the image in the specified ImageFormat. + + Image format to save the file in, for example ImageFormat.Tiff + Save original/user-defined resolution + + + // Save image to file system in the selected format + image.SaveImage(@"C:\MyImages\Output.tif", ImageFormat.Tiff, true); + + + + Generic method that will save the image in the specified ImageFormat. + + Image format to save the file in, for example ImageFormat.Tiff + + + // Save image to file system in the selected format + image.SaveImage(@"C:\MyImages\Output.tif", ImageFormat.Tiff); + + + + Byte array matching PixelFormat.Format32bppArgb (bgrA in real life). + + + + Lock bits in bitmap for direct access + + + + + + Unlock bits in bitmap after direct access + + + + + Apply a filter to the current Image. + Any filter that supports the IFilter interface + + + + + Rotates, flips, or rotates and flips the image + + The type of rotation and flip to apply to the image + + + Int array matching PixelFormat.Format32bppArgb (bgrA in real life) + + + + + + + + Dispose + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Focal point scaling. Similar to crop scaling but allow you to set the focal point around which the cropping will be centered. + + + + + Focal point scaling. Similar to crop scaling but allow you to set the focal point around which the cropping will be centered. + + Target width + Target height + Value between 0.0 (left side) and 1.0 (right side) + Value between 0.0 (top side) and 1.0 (bottom side) + + + + + + + + + + + + + + + + + + + + + + + + + Abstract class used by scaling engines. + + + + + + Core function that applies the scaling to the image. + Image to be scaled + Scaled image + + + Core function that applies the scaling to the image with the option to prevent upscaling + + + Scaled image + + + + Controls if target size is larger than original size + + + + + + + + + + diff --git a/NetImageLibrary.Core/Properties/AssemblyInfo.cs b/NetImageLibrary.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2e70f8e --- /dev/null +++ b/NetImageLibrary.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("58b4262b-c04f-4c08-a1c9-948ddd0cbf84")] diff --git a/Scaling/CropScaling.cs b/NetImageLibrary.Core/Scaling/CropScaling.cs similarity index 100% rename from Scaling/CropScaling.cs rename to NetImageLibrary.Core/Scaling/CropScaling.cs diff --git a/Scaling/FitScaling.cs b/NetImageLibrary.Core/Scaling/FitScaling.cs similarity index 100% rename from Scaling/FitScaling.cs rename to NetImageLibrary.Core/Scaling/FitScaling.cs diff --git a/NetImageLibrary.Core/Scaling/FocalPointScaling.cs b/NetImageLibrary.Core/Scaling/FocalPointScaling.cs new file mode 100644 index 0000000..b5f9cb6 --- /dev/null +++ b/NetImageLibrary.Core/Scaling/FocalPointScaling.cs @@ -0,0 +1,72 @@ +#pragma warning disable 1591 +namespace Kaliko.ImageLibrary.Scaling { + using System; + using System.Drawing; + + /// + /// Focal point scaling. Similar to crop scaling but allow you to set the focal point around which the cropping will be centered. + /// + public class FocalPointScaling : ScalingBase { + private readonly double _focalPointX; + private readonly double _focalPointY; + private readonly Size _targetSize; + + /// + /// Focal point scaling. Similar to crop scaling but allow you to set the focal point around which the cropping will be centered. + /// + /// Target width + /// Target height + /// Value between 0.0 (left side) and 1.0 (right side) + /// Value between 0.0 (top side) and 1.0 (bottom side) + public FocalPointScaling(int targetWidth, int targetHeight, double focalPointX, double focalPointY) : base(targetWidth, targetHeight) { + _focalPointX = focalPointX; + _focalPointY = focalPointY; + _targetSize = new Size(targetWidth, targetHeight); + } + + internal override Size CalculateNewImageSize(Size originalSize) { + var targetRatio = GetRatio(_targetSize); + var originalRatio = GetRatio(originalSize); + + var size = new Size(_targetSize.Width, _targetSize.Height); + + if (originalRatio < targetRatio) + { + size.Height = (originalSize.Height * _targetSize.Width) / originalSize.Width; + } + else + { + size.Width = (originalSize.Width * _targetSize.Height) / originalSize.Height; + } + + return size; + } + + internal override KalikoImage DrawResizedImage(KalikoImage sourceImage, Size calculatedSize, Size originalSize) { + var resizedImage = new KalikoImage(_targetSize, sourceImage.BackgroundColor); + + var scaledFocalPointX = _focalPointX / ((double)(calculatedSize.Width - _targetSize.Width) / calculatedSize.Width); + var scaledFocalPointY = _focalPointY / ((double)(calculatedSize.Height - _targetSize.Height) / calculatedSize.Height); + + var sourceX = (int)Math.Round((_targetSize.Width - calculatedSize.Width) * scaledFocalPointX) + (_targetSize.Width / 2); + if (sourceX < _targetSize.Width - calculatedSize.Width) { + sourceX = _targetSize.Width - calculatedSize.Width; + } + else if (sourceX > 0) { + sourceX = 0; + } + + var sourceY = (int)Math.Round((_targetSize.Height - calculatedSize.Height) * scaledFocalPointY) + (_targetSize.Height / 2); + if (sourceY < _targetSize.Height - calculatedSize.Height) { + sourceY = _targetSize.Height - calculatedSize.Height; + } + else if (sourceY > 0) { + sourceY = 0; + } + + KalikoImage.DrawScaledImage(resizedImage, sourceImage, sourceX, sourceY, calculatedSize.Width, calculatedSize.Height); + + return resizedImage; + } + } +} \ No newline at end of file diff --git a/Scaling/PadScaling.cs b/NetImageLibrary.Core/Scaling/PadScaling.cs similarity index 100% rename from Scaling/PadScaling.cs rename to NetImageLibrary.Core/Scaling/PadScaling.cs diff --git a/Scaling/ScalingBase.cs b/NetImageLibrary.Core/Scaling/ScalingBase.cs similarity index 96% rename from Scaling/ScalingBase.cs rename to NetImageLibrary.Core/Scaling/ScalingBase.cs index 158c95e..df5ef46 100644 --- a/Scaling/ScalingBase.cs +++ b/NetImageLibrary.Core/Scaling/ScalingBase.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary.Scaling { using System.Drawing; diff --git a/TextField.cs b/NetImageLibrary.Core/TextField.cs similarity index 96% rename from TextField.cs rename to NetImageLibrary.Core/TextField.cs index fef5520..9a89fe2 100644 --- a/TextField.cs +++ b/NetImageLibrary.Core/TextField.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary { using System.Drawing; using System.Drawing.Drawing2D; diff --git a/TextShadow.cs b/NetImageLibrary.Core/TextShadow.cs similarity index 95% rename from TextShadow.cs rename to NetImageLibrary.Core/TextShadow.cs index a062dc5..608440d 100644 --- a/TextShadow.cs +++ b/NetImageLibrary.Core/TextShadow.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary { using System.Drawing; diff --git a/ThumbnailMethod.cs b/NetImageLibrary.Core/ThumbnailMethod.cs similarity index 95% rename from ThumbnailMethod.cs rename to NetImageLibrary.Core/ThumbnailMethod.cs index 6ea614a..05a710c 100644 --- a/ThumbnailMethod.cs +++ b/NetImageLibrary.Core/ThumbnailMethod.cs @@ -25,6 +25,7 @@ */ #endregion +#pragma warning disable 1591 namespace Kaliko.ImageLibrary { using System; diff --git a/FastFilters/FastBrightnessFilter.cs b/NetImageLibrary.FastFilters/FastBrightnessFilter.cs similarity index 100% rename from FastFilters/FastBrightnessFilter.cs rename to NetImageLibrary.FastFilters/FastBrightnessFilter.cs diff --git a/FastFilters/FastChromaKeyFilter.cs b/NetImageLibrary.FastFilters/FastChromaKeyFilter.cs similarity index 100% rename from FastFilters/FastChromaKeyFilter.cs rename to NetImageLibrary.FastFilters/FastChromaKeyFilter.cs diff --git a/FastFilters/FastContrastFilter.cs b/NetImageLibrary.FastFilters/FastContrastFilter.cs similarity index 100% rename from FastFilters/FastContrastFilter.cs rename to NetImageLibrary.FastFilters/FastContrastFilter.cs diff --git a/FastFilters/FastDesaturationFilter.cs b/NetImageLibrary.FastFilters/FastDesaturationFilter.cs similarity index 100% rename from FastFilters/FastDesaturationFilter.cs rename to NetImageLibrary.FastFilters/FastDesaturationFilter.cs diff --git a/FastFilters/FastGaussianBlur.cs b/NetImageLibrary.FastFilters/FastGaussianBlur.cs similarity index 100% rename from FastFilters/FastGaussianBlur.cs rename to NetImageLibrary.FastFilters/FastGaussianBlur.cs diff --git a/FastFilters/FastInvertFilter.cs b/NetImageLibrary.FastFilters/FastInvertFilter.cs similarity index 100% rename from FastFilters/FastInvertFilter.cs rename to NetImageLibrary.FastFilters/FastInvertFilter.cs diff --git a/FastFilters/FastUnsharpMaskFilter.cs b/NetImageLibrary.FastFilters/FastUnsharpMaskFilter.cs similarity index 100% rename from FastFilters/FastUnsharpMaskFilter.cs rename to NetImageLibrary.FastFilters/FastUnsharpMaskFilter.cs diff --git a/NetImageLibrary.FastFilters/NetImageLibrary.FastFilters.csproj b/NetImageLibrary.FastFilters/NetImageLibrary.FastFilters.csproj new file mode 100644 index 0000000..6ec6622 --- /dev/null +++ b/NetImageLibrary.FastFilters/NetImageLibrary.FastFilters.csproj @@ -0,0 +1,75 @@ + + + + netcoreapp2.0;netstandard2.0;net40;net461;net5.0 + 4.0-beta1 + true + Kaliko.ImageLibrary.FastFilters + false + ImageLibrary.FastFilters + https://kaliko.com/image-library/ + https://kaliko.com/external/imagelibrary-logo.png + MIT + https://github.com/fschultz/NetImageLibrary + Fredrik Schultz / Kaliko + Fredrik Schultz and Contributors + Optimized multi-threaded graphical filters for .NET Image Library to use in full trust environments. Including gaussian blur, unsharp mask, brightness, contrast, chroma key and more. + .NET Image Library Fast Filters + image resize crop thumbnail filters unsharpen chromakey + + true + * Migrated projects to be compatible with .NET 4.x and Core + + + + + + + + + + + + + + + + NETSTANDARD;NETSTANDARD2_0 + + + + + NETCOREAPP;NETCOREAPP2_0 + + + + + NETCOREAPP;NET5_0 + + + + + NET46;NETFULL + + + + + + + + + + + + + NET46;NETFULL + + + + + + + + + + diff --git a/NetImageLibrary.FastFilters/Properties/AssemblyInfo.cs b/NetImageLibrary.FastFilters/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..084858a --- /dev/null +++ b/NetImageLibrary.FastFilters/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2e583ffe-2595-4888-8116-a6c92e15f3d8")] diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 18c1b41..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Kaliko Image Library")] -[assembly: AssemblyDescription(".NET library for easy image handling like cropping, thumbnails, streaming and more")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Kaliko")] -[assembly: AssemblyProduct("ImageLibrary")] -[assembly: AssemblyCopyright("Copyright © Fredrik Schultz and Contributors")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("58b4262b-c04f-4c08-a1c9-948ddd0cbf84")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -//[assembly: AssemblyVersion("2.0.6.0")] -//[assembly: AssemblyFileVersion("2.0.6.0")] diff --git a/Properties/SolutionInfo.cs b/Properties/SolutionInfo.cs deleted file mode 100644 index 1bbaf27..0000000 --- a/Properties/SolutionInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -// -using System.Reflection; - -[assembly: AssemblyVersionAttribute("3.0.2")] -[assembly: AssemblyFileVersionAttribute("3.0.2")] -namespace System { - internal static class AssemblyVersionInformation { - internal const string Version = "3.0.2"; - } -} diff --git a/README.md b/README.md index 478eee2..a3b8fc1 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,153 @@ Current build contains the following filters: If you plan using this library with WPF or simular, read this post on how to convert an KalikoImage object to System.Windows.Media.Imaging.BitmapImage and System.Windows.Controls.Image. +## Examples + +### Crop scaling +Scale by cropping the image to cover the requested width and height: +```csharp + using (var image = new KalikoImage(ImageFilePath)) { + image + .Scale(new CropScaling(500, 500)) + .SaveJpg(OutputFilePath, 80); + } +``` + +### Fit scaling +Scale by fitting the image inside the requested width and height: +```csharp + using (var image = new KalikoImage(ImageFilePath)) { + image + .Scale(new FitScaling(500, 500)) + .SaveJpg(OutputFilePath, 80); + } +``` + +### Pad scaling +Scale by fitting the image inside the requested width and height and then pad to the width and height using colour: +```csharp + using (var image = new KalikoImage(ImageFilePath)) { + image + .Scale(new PadScaling(500, 500, Color.Crimson)) + .SaveJpg(OutputFilePath, 80); + } +``` + +### Focal point scaling +Similar to the crop scaling but takes a focal point as parameter to determine the point of interest when cropping the image: +```csharp + using (var image = new KalikoImage(ImageFilePath)) { + image + .Scale(new FocalPointScaling(500, 500, 0.75, 1)) + .SaveJpg(OutputFilePath, 80); + } +``` + +### Brightness filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastBrightnessFilter(50)); + image.SaveJpg(OutputPath, 80); + } +``` + +### Contrast filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastContrastFilter(50)); + image.SaveJpg(OutputPath, 80); + } +``` + +### Chroma key filter (green screen) +```csharp + using (var image = new KalikoImage("c:\\images\\greenscreen.jpg"))) { + // Make green screen parts transparent + image.ApplyFilter(new FastChromaKeyFilter(Color.FromArgb(13, 161, 37), 40, 0.5f, 0.75f)); + + using (var background = new KalikoImage("c:\\images\\backdrop.jpg")) { + // Apply cleaned green screen image over backdrop + background.BlitImage(image); + background.SaveJpg(OutputPath, 80); + } + } +``` + +### Desaturate filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastDesaturationFilter()); + image.SaveJpg(OutputPath, 80); + } +``` + +### Gaussian blur filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastGaussianBlurFilter(1.1f)); + image.SaveJpg(OutputPath, 80); + } +``` + +### Invert filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastInvertFilter()); + image.SaveJpg(OutputPath, 80); + } +``` + +### Unsharp mask filter +```csharp + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastUnsharpMaskFilter(1.1f, 0.44f, 0)); + image.SaveJpg(OutputPath, 80); + } +``` + +### Draw text +```csharp + using (var image = new KalikoImage(ImagePath)) { + var text = new TextField("Lorem ipsum") { + Alignment = StringAlignment.Center, + VerticalAlignment = StringAlignment.Center, + Outline = 5, + OutlineColor = Color.Red, + Font = new Font("Arial", 60), + Rotation = 30f, + TextColor = Color.DarkOrange, + TextShadow = new TextShadow(Color.FromArgb(128, 0, 0, 0), 4, 4) + }; + image.DrawText(text); + image.SaveJpg(OutputPath, 80); + } +``` + +### Gradient fill +```csharp + using (var image = new KalikoImage(ImagePath)) + { + image.GradientFill(Color.FromArgb(128, 255, 200, 90), Color.FromArgb(128, 255, 64, 0)); + image.SaveJpg(OutputPath, 80); + } +``` + +### Watermark +```csharp + using (var image = new KalikoImage(ImagePath)) + { + image.BlitFill("c:\\images\\semi-transparent-watermark.png")); + image.SaveJpg(OutputPath, 80); + } +``` + + ## History + +**4.0.0** +* Migrated projects to be compatible with .NET 4.x and Core +* Added FocalPointScaling as an alternative to crop scaling but that allows to define the point of interest + **3.0.2** * Fixed bug where BlitFill doesn't properly fill portrait sized images diff --git a/ReleaseNotes.md b/ReleaseNotes.md index c20edc6..47e578c 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,3 +1,8 @@ +### New in 4.0.0 +* Migrated projects to be compatible with .NET 4.x, Core 2.x and Standard 2.x +* Added FocalPointScaling as an alternative to crop scaling but that allows to define the point of interest +* Thanks to rbrian for pull request! + ### New in 3.0.2 * Fixed bug where BlitFill doesn't properly fill portrait sized images diff --git a/TestApp/Program.cs b/TestApp/Program.cs deleted file mode 100644 index 12639d1..0000000 --- a/TestApp/Program.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Drawing; -using Kaliko.ImageLibrary; -using Kaliko.ImageLibrary.Filters; - -namespace TestApp { - using Kaliko.ImageLibrary.Scaling; - - class Program { - static void Main(string[] args) { - KalikoImage image = new KalikoImage("testimage.jpg"); - image.BackgroundColor = Color.Aquamarine; - - image.Scale(new FitScaling(100, 100)).SaveJpg("thumbnail-fit.jpg", 90); - - image.Scale(new CropScaling(100,100)).SaveJpg("thumbnail-crop.jpg", 90); - - image.Scale(new PadScaling(100, 100)).SaveJpg("thumbnail-pad.jpg", 90); - - KalikoImage sharpimg = image.Scale(new CropScaling(100, 100)); - sharpimg.ApplyFilter(new UnsharpMaskFilter(1.2f, 0.3f, 1)); - sharpimg.SaveJpg("thumbnail-unsharpened.jpg", 90); - - sharpimg.ApplyFilter(new DesaturationFilter()); - sharpimg.SaveJpg("thumbnail-gray.jpg", 90); - - sharpimg.ApplyFilter(new ContrastFilter(30)); - sharpimg.SaveJpg("thumbnail-contrast.jpg", 90); - - } - } -} diff --git a/TestApp/TestApp.csproj b/TestApp/TestApp.csproj deleted file mode 100644 index ea4bcc9..0000000 --- a/TestApp/TestApp.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {4381B75F-8E8B-4F82-AABC-A16AD72D201A} - Exe - Properties - TestApp - TestApp - v2.0 - - - - - 2.0 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - {073C7180-35E8-442A-9334-AA3F529C0985} - ImageLibrary - - - - - Always - - - - - \ No newline at end of file diff --git a/TestApp/TestApp.csproj.user b/TestApp/TestApp.csproj.user deleted file mode 100644 index 9c97dae..0000000 --- a/TestApp/TestApp.csproj.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - ProjectFiles - - \ No newline at end of file diff --git a/TestApp/testimage.jpg b/TestApp/testimage.jpg deleted file mode 100644 index a975385..0000000 Binary files a/TestApp/testimage.jpg and /dev/null differ diff --git a/TestAppNet461/App.config b/TestAppNet461/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/TestAppNet461/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TestAppNet461/Program.cs b/TestAppNet461/Program.cs new file mode 100644 index 0000000..8a9260e --- /dev/null +++ b/TestAppNet461/Program.cs @@ -0,0 +1,205 @@ +namespace TestAppNet461 +{ + using System; + using System.Drawing; + using System.IO; + using System.Reflection; + using Kaliko.ImageLibrary; + using Kaliko.ImageLibrary.FastFilters; + using Kaliko.ImageLibrary.Scaling; + + class Program + { + private static string AppPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + private static string ImagePath = Path.GetFullPath(AppPath + "\\..\\..\\vincent-guth-183404-unsplash.jpg"); // Sample photo by Vincent Guth @vingtcent + private static string OutputPath = Path.GetFullPath(AppPath + "\\..\\..\\output/"); + + static void Main(string[] args) + { + Console.WriteLine("Demo application for .NET Image Library [.NET 4.61]"); + + // Scaling + CropScale(); + FitScale(); + FocalPointScale(); + PadScale(); + + // Filters + Brightness(); + ChromaKey(); + Contrast(); + Desaturate(); + GaussianBlur(); + Invert(); + UnsharpMask(); + + // Functions + DrawText(); + GradientFill(); + Watermark(); + } + + #region Scaling + + private static void CropScale() + { + using (var image = new KalikoImage(ImagePath)) + { + image + .Scale(new CropScaling(500, 500)) + .SaveJpg($"{OutputPath}cropscale.jpg", 80); + } + } + + private static void FitScale() + { + using (var image = new KalikoImage(ImagePath)) + { + image + .Scale(new FitScaling(500, 500)) + .SaveJpg($"{OutputPath}fitscale.jpg", 80); + } + } + + private static void PadScale() + { + using (var image = new KalikoImage(ImagePath)) + { + image + .Scale(new PadScaling(500, 500, Color.Crimson)) + .SaveJpg($"{OutputPath}padscale.jpg", 80); + } + } + + private static void FocalPointScale() + { + using (var image = new KalikoImage(ImagePath)) + { + image + .Scale(new FocalPointScaling(500, 500, 1, 1)) + .SaveJpg($"{OutputPath}focalpointscale.jpg", 80); + } + } + + #endregion Scaling + + #region Filters + + // Note: Unless your application is running in medium trust environment, always use the FastFilters-version of the filter + + private static void Brightness() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastBrightnessFilter(50)); + image.SaveJpg($"{OutputPath}brightness.jpg", 80); + } + } + + private static void Contrast() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastContrastFilter(50)); + image.SaveJpg($"{OutputPath}contrast.jpg", 80); + } + } + + private static void ChromaKey() + { + using (var image = new KalikoImage(Path.GetFullPath(AppPath + "\\..\\..\\jcvd-green-screen.jpg"))) + { + image.ApplyFilter(new FastChromaKeyFilter(Color.FromArgb(13, 161, 37), 40, 0.5f, 0.75f)); + image.SavePng($"{OutputPath}chromakey.png"); + + using (var background = new KalikoImage(ImagePath)) + { + var scaledBackground = background.Scale(new FocalPointScaling(640, 320, 0, 1)); + scaledBackground.BlitImage(image); + scaledBackground.SaveJpg($"{OutputPath}chromakey.jpg", 80); + } + } + } + + private static void Desaturate() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastDesaturationFilter()); + image.SaveJpg($"{OutputPath}desaturate.jpg", 80); + } + } + + private static void GaussianBlur() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastGaussianBlurFilter(1.1f)); + image.SaveJpg($"{OutputPath}gaussianblur.jpg", 80); + } + } + + private static void Invert() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastInvertFilter()); + image.SaveJpg($"{OutputPath}invert.jpg", 80); + } + } + + private static void UnsharpMask() + { + using (var image = new KalikoImage(ImagePath)) + { + image.ApplyFilter(new FastUnsharpMaskFilter(1.1f, 0.44f, 0)); + image.SaveJpg($"{OutputPath}unsharpmask.jpg", 80); + } + } + + #endregion Filters + + #region Functions + + private static void DrawText() + { + using (var image = new KalikoImage(ImagePath)) + { + var text = new TextField("Lorem ipsum") + { + Alignment = StringAlignment.Center, + VerticalAlignment = StringAlignment.Center, + Outline = 5, + OutlineColor = Color.Red, + Font = new Font("Arial", 60), + Rotation = 30f, + TextColor = Color.DarkOrange, + TextShadow = new TextShadow(Color.FromArgb(128, 0, 0, 0), 4, 4) + }; + image.DrawText(text); + image.SaveJpg($"{OutputPath}text.jpg", 80); + } + } + + private static void GradientFill() + { + using (var image = new KalikoImage(ImagePath)) + { + image.GradientFill(Color.FromArgb(128, 255, 200, 90), Color.FromArgb(128, 255, 64, 0)); + image.SaveJpg($"{OutputPath}gradientfill.jpg", 80); + } + } + + private static void Watermark() + { + using (var image = new KalikoImage(ImagePath)) + { + image.BlitFill(Path.GetFullPath(AppPath + "\\..\\..\\watermark.png")); + image.SaveJpg($"{OutputPath}watermark.jpg", 80); + } + } + + #endregion Functions + + } +} diff --git a/TestApp/Properties/AssemblyInfo.cs b/TestAppNet461/Properties/AssemblyInfo.cs similarity index 68% rename from TestApp/Properties/AssemblyInfo.cs rename to TestAppNet461/Properties/AssemblyInfo.cs index 2043834..a42a07e 100644 --- a/TestApp/Properties/AssemblyInfo.cs +++ b/TestAppNet461/Properties/AssemblyInfo.cs @@ -1,33 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestApp")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("TestApp")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("384d6779-1819-4814-a894-496bf44bace1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestAppNet461")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestAppNet461")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1d6039a4-5d21-4454-bd74-59a395019401")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestAppNet461/TestAppNet461.csproj b/TestAppNet461/TestAppNet461.csproj new file mode 100644 index 0000000..8a03cf3 --- /dev/null +++ b/TestAppNet461/TestAppNet461.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {1D6039A4-5D21-4454-BD74-59A395019401} + Exe + TestAppNet461 + TestAppNet461 + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + {073c7180-35e8-442a-9334-aa3f529c0985} + NetImageLibrary.Core + + + {8f14659b-df8b-45ed-a5cb-72f09dc44df1} + NetImageLibrary.FastFilters + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestAppNet461/jcvd-green-screen.jpg b/TestAppNet461/jcvd-green-screen.jpg new file mode 100644 index 0000000..82e2dcf Binary files /dev/null and b/TestAppNet461/jcvd-green-screen.jpg differ diff --git a/TestAppNet461/output/Empty.txt b/TestAppNet461/output/Empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/TestAppNet461/vincent-guth-183404-unsplash.jpg b/TestAppNet461/vincent-guth-183404-unsplash.jpg new file mode 100644 index 0000000..aaaa4d3 Binary files /dev/null and b/TestAppNet461/vincent-guth-183404-unsplash.jpg differ diff --git a/TestAppNet461/watermark.png b/TestAppNet461/watermark.png new file mode 100644 index 0000000..17961e4 Binary files /dev/null and b/TestAppNet461/watermark.png differ diff --git a/TestAppNetCore/Program.cs b/TestAppNetCore/Program.cs new file mode 100644 index 0000000..d390aa0 --- /dev/null +++ b/TestAppNetCore/Program.cs @@ -0,0 +1,176 @@ +namespace TestAppNetCore { + using System; + using System.Drawing; + using System.IO; + using System.Reflection; + using Kaliko.ImageLibrary; + using Kaliko.ImageLibrary.FastFilters; + using Kaliko.ImageLibrary.Scaling; + + class Program { + private static string AppPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + private static string ImagePath = Path.GetFullPath(AppPath + "\\..\\..\\..\\vincent-guth-183404-unsplash.jpg"); // Sample photo by Vincent Guth @vingtcent + private static string OutputPath = Path.GetFullPath(AppPath + "\\..\\..\\..\\output/"); + + static void Main(string[] args) { + Console.WriteLine("Demo application for .NET Image Library [.NET Core]"); + + // Scaling + CropScale(); + FitScale(); + FocalPointScale(); + PadScale(); + + // Filters + Brightness(); + ChromaKey(); + Contrast(); + Desaturate(); + GaussianBlur(); + Invert(); + UnsharpMask(); + + // Functions + DrawText(); + GradientFill(); + Watermark(); + } + + #region Scaling + + private static void CropScale() { + using (var image = new KalikoImage(ImagePath)) { + image + .Scale(new CropScaling(500, 500)) + .SaveJpg($"{OutputPath}cropscale.jpg", 80); + } + } + + private static void FitScale() { + using (var image = new KalikoImage(ImagePath)) { + image + .Scale(new FitScaling(500, 500)) + .SaveJpg($"{OutputPath}fitscale.jpg", 80); + } + } + + private static void PadScale() { + using (var image = new KalikoImage(ImagePath)) { + image + .Scale(new PadScaling(500, 500, Color.Crimson)) + .SaveJpg($"{OutputPath}padscale.jpg", 80); + } + } + + private static void FocalPointScale() { + using (var image = new KalikoImage(ImagePath)) { + image + .Scale(new FocalPointScaling(500, 500, 1, 1)) + .SaveJpg($"{OutputPath}focalpointscale.jpg", 80); + } + } + + #endregion Scaling + + #region Filters + + // Note: Unless your application is running in medium trust environment, always use the FastFilters-version of the filter + + private static void Brightness() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastBrightnessFilter(50)); + image.SaveJpg($"{OutputPath}brightness.jpg", 80); + } + } + + private static void Contrast() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastContrastFilter(50)); + image.SaveJpg($"{OutputPath}contrast.jpg", 80); + } + } + + private static void ChromaKey() { + using (var image = new KalikoImage(Path.GetFullPath(AppPath + "\\..\\..\\..\\jcvd-green-screen.jpg"))) { + image.ApplyFilter(new FastChromaKeyFilter(Color.FromArgb(13, 161, 37), 40, 0.5f, 0.75f)); + image.SavePng($"{OutputPath}chromakey.png"); + + using (var background = new KalikoImage(ImagePath)) { + var scaledBackground = background.Scale(new FocalPointScaling(640, 320, 0, 1)); + scaledBackground.BlitImage(image); + scaledBackground.SaveJpg($"{OutputPath}chromakey.jpg", 80); + } + } + } + + private static void Desaturate() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastDesaturationFilter()); + image.SaveJpg($"{OutputPath}desaturate.jpg", 80); + } + } + + private static void GaussianBlur() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastGaussianBlurFilter(1.1f)); + image.SaveJpg($"{OutputPath}gaussianblur.jpg", 80); + } + } + + private static void Invert() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastInvertFilter()); + image.SaveJpg($"{OutputPath}invert.jpg", 80); + } + } + + private static void UnsharpMask() { + using (var image = new KalikoImage(ImagePath)) { + image.ApplyFilter(new FastUnsharpMaskFilter(1.1f, 0.44f, 0)); + image.SaveJpg($"{OutputPath}unsharpmask.jpg", 80); + } + } + + #endregion Filters + + #region Functions + + private static void DrawText() { + using (var image = new KalikoImage(ImagePath)) { + var text = new TextField("Lorem ipsum") { + Alignment = StringAlignment.Center, + VerticalAlignment = StringAlignment.Center, + Outline = 5, + OutlineColor = Color.Red, + Font = new Font("Arial", 60), + Rotation = 30f, + TextColor = Color.DarkOrange, + TextShadow = new TextShadow(Color.FromArgb(128, 0, 0, 0), 4, 4) + }; + image.DrawText(text); + image.SaveJpg($"{OutputPath}text.jpg", 80); + } + } + + private static void GradientFill() + { + using (var image = new KalikoImage(ImagePath)) + { + image.GradientFill(Color.FromArgb(128, 255, 200, 90), Color.FromArgb(128, 255, 64, 0)); + image.SaveJpg($"{OutputPath}gradientfill.jpg", 80); + } + } + + private static void Watermark() + { + using (var image = new KalikoImage(ImagePath)) + { + image.BlitFill(Path.GetFullPath(AppPath + "\\..\\..\\..\\watermark.png")); + image.SaveJpg($"{OutputPath}watermark.jpg", 80); + } + } + + #endregion Functions + } +} + diff --git a/TestAppNetCore/TestAppNetCore.csproj b/TestAppNetCore/TestAppNetCore.csproj new file mode 100644 index 0000000..7826410 --- /dev/null +++ b/TestAppNetCore/TestAppNetCore.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + + + + + + + + diff --git a/TestAppNetCore/jcvd-green-screen.jpg b/TestAppNetCore/jcvd-green-screen.jpg new file mode 100644 index 0000000..82e2dcf Binary files /dev/null and b/TestAppNetCore/jcvd-green-screen.jpg differ diff --git a/TestAppNetCore/output/Empty.txt b/TestAppNetCore/output/Empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/TestAppNetCore/vincent-guth-183404-unsplash.jpg b/TestAppNetCore/vincent-guth-183404-unsplash.jpg new file mode 100644 index 0000000..aaaa4d3 Binary files /dev/null and b/TestAppNetCore/vincent-guth-183404-unsplash.jpg differ diff --git a/TestAppNetCore/watermark.png b/TestAppNetCore/watermark.png new file mode 100644 index 0000000..17961e4 Binary files /dev/null and b/TestAppNetCore/watermark.png differ