[nwd] Replacing image lib references where necessary

After analyzing appsheets usage of epplus it was found that the only
functionality which interacts with System.Drawing.Common are:

ExcelWorksheet, uses Color functions
ExcelChartsheet, embeds chart image in worksheet.
Worksheet using Compatibility for system.drawing.common so switched the
core compatibility to use ironsoftware.
Worksheets using some image apis.
ExcelVmlDrawingPicture, also switched to use IronSoftware.

These were the only locations that appsheet uses Epplus where
drawing functionality was being implemented.

b/323543312

Change-Id: I68c2951c21f25c25164755f5d5b8839afc5e13e3
diff --git a/EPPlus/Compatibility/ImageCompat.cs b/EPPlus/Compatibility/ImageCompat.cs
index ec0eef3..e7aefde 100644
--- a/EPPlus/Compatibility/ImageCompat.cs
+++ b/EPPlus/Compatibility/ImageCompat.cs
@@ -1,37 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Imaging;
 using System.IO;
-using System.Linq;
-using System.Text;
+using IronSoftware.Drawing;
 
 namespace OfficeOpenXml.Compatibility
 {
     internal class ImageCompat
     {
-        internal static byte[] GetImageAsByteArray(Image image)
+        internal static byte[] GetImageAsByteArray(AnyBitmap image)
         {
             var ms = new MemoryStream();
-            if (image.RawFormat.Guid == ImageFormat.Gif.Guid)
+            if (image.GetImageFormat() == AnyBitmap.ImageFormat.Gif ||
+                image.GetImageFormat() == AnyBitmap.ImageFormat.Bmp ||
+                image.GetImageFormat() == AnyBitmap.ImageFormat.Png ||
+                image.GetImageFormat() == AnyBitmap.ImageFormat.Tiff)
             {
-                image.Save(ms, ImageFormat.Gif);
-            }
-            else if (image.RawFormat.Guid == ImageFormat.Bmp.Guid)
-            {
-                image.Save(ms, ImageFormat.Bmp);
-            }
-            else if (image.RawFormat.Guid == ImageFormat.Png.Guid)
-            {
-                image.Save(ms, ImageFormat.Png);
-            }
-            else if (image.RawFormat.Guid == ImageFormat.Tiff.Guid)
-            {
-                image.Save(ms, ImageFormat.Tiff);
+                image.ExportStream(ms, image.GetImageFormat());
             }
             else
             {
-                image.Save(ms, ImageFormat.Jpeg);
+                image.ExportStream(ms, AnyBitmap.ImageFormat.Jpeg);
             }
 
             return ms.ToArray();
diff --git a/EPPlus/Drawing/ExcelDrawings.cs b/EPPlus/Drawing/ExcelDrawings.cs
index 8441e56..97a1483 100644
--- a/EPPlus/Drawing/ExcelDrawings.cs
+++ b/EPPlus/Drawing/ExcelDrawings.cs
@@ -35,8 +35,8 @@
 using System.Xml;
 using System.Collections;
 using System.IO;
-using System.Drawing;
 using System.Linq;
+using IronSoftware.Drawing;
 using OfficeOpenXml.Drawing.Chart;
 using OfficeOpenXml.Table.PivotTable;
 using OfficeOpenXml.Utils;
@@ -304,7 +304,7 @@
             /// <param name="Name"></param>
             /// <param name="image">An image. Allways saved in then JPeg format</param>
             /// <returns></returns>
-            public ExcelPicture AddPicture(string Name, Image image)
+            public ExcelPicture AddPicture(string Name, AnyBitmap image)
             {
                return AddPicture(Name, image, null);
             }
@@ -315,7 +315,7 @@
             /// <param name="image">An image. Allways saved in then JPeg format</param>
             /// <param name="Hyperlink">Picture Hyperlink</param>
             /// <returns></returns>
-            public ExcelPicture AddPicture(string Name, Image image, Uri Hyperlink)
+            public ExcelPicture AddPicture(string Name, AnyBitmap image, Uri Hyperlink)
             {
                 if (image != null)
                 {
diff --git a/EPPlus/Drawing/ExcelPicture.cs b/EPPlus/Drawing/ExcelPicture.cs
index 59e8cf1..213dd24 100644
--- a/EPPlus/Drawing/ExcelPicture.cs
+++ b/EPPlus/Drawing/ExcelPicture.cs
@@ -35,9 +35,8 @@
 using System.Text;
 using System.Xml;
 using System.IO;
-using System.Drawing;
-using System.Drawing.Imaging;
 using System.Diagnostics;
+using IronSoftware.Drawing;
 using OfficeOpenXml.Compatibility;
 using OfficeOpenXml.Utils;
 
@@ -61,7 +60,7 @@
                 Part = drawings.Part.Package.GetPart(UriPic);
                 FileInfo f = new FileInfo(UriPic.OriginalString);
                 ContentType = GetContentType(f.Extension);
-                _image = Image.FromStream(Part.GetStream());
+                _image = AnyBitmap.FromStream(Part.GetStream());
 #if (Core)
                 byte[] iby = ImageCompat.GetImageAsByteArray(_image);
 #else
@@ -87,11 +86,11 @@
                 }
             }
         }
-        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Image image) :
+        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, AnyBitmap image) :
            this(drawings, node, image, null)
         {
         }
-        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Image image, Uri hyperlink) :
+        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, AnyBitmap image, Uri hyperlink) :
             base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
         {
             XmlElement picNode = node.OwnerDocument.CreateElement("xdr", "pic", ExcelPackage.schemaSheetDrawings);
@@ -130,7 +129,7 @@
             var package = drawings.Worksheet._package.Package;
             ContentType = GetContentType(imageFile.Extension);
             var imagestream = new FileStream(imageFile.FullName, FileMode.Open, FileAccess.Read);
-            _image = Image.FromStream(imagestream);
+            _image = AnyBitmap.FromStream(imagestream);
 #if (Core)
             var img=ImageCompat.GetImageAsByteArray(_image);
 #else
@@ -205,7 +204,7 @@
             //_drawings._pics.Add(newPic);
         }
         #endregion
-        private string SavePicture(Image image)
+        private string SavePicture(AnyBitmap image)
         {
 #if (Core)
             byte[] img = ImageCompat.GetImageAsByteArray(image);
@@ -237,11 +236,11 @@
 
             return RelPic.Id;
         }
-        private void SetPosDefaults(Image image)
+        private void SetPosDefaults(AnyBitmap image)
         {
             EditAs = eEditAs.OneCell;
-            SetPixelWidth(image.Width, image.HorizontalResolution);
-            SetPixelHeight(image.Height, image.VerticalResolution);
+            SetPixelWidth(image.Width, (float)image.HorizontalResolution.Value);
+            SetPixelHeight(image.Height, (float)image.VerticalResolution.Value);
         }
 
         private string PicStartXml()
@@ -280,11 +279,11 @@
         }
 
         internal string ImageHash { get; set; }
-        Image _image = null;
+        AnyBitmap _image = null;
         /// <summary>
         /// The Image
         /// </summary>
-        public Image Image
+        public AnyBitmap Image
         {
             get
             {
@@ -310,12 +309,12 @@
                 }
             }
         }
-        ImageFormat _imageFormat=ImageFormat.Jpeg;
+        AnyBitmap.ImageFormat _imageFormat=AnyBitmap.ImageFormat.Jpeg;
         /// <summary>
         /// Image format
         /// If the picture is created from an Image this type is always Jpeg
         /// </summary>
-        public ImageFormat ImageFormat
+        public AnyBitmap.ImageFormat ImageFormat
         {
             get
             {
@@ -350,8 +349,8 @@
                 width = (int)(width * ((decimal)Percent / 100));
                 height = (int)(height * ((decimal)Percent / 100));
 
-                SetPixelWidth(width, Image.HorizontalResolution);
-                SetPixelHeight(height, Image.VerticalResolution);
+                SetPixelWidth(width, (float)Image.HorizontalResolution.Value);
+                SetPixelHeight(height, (float)Image.VerticalResolution.Value);
             }
         }
         internal Uri UriPic { get; set; }
diff --git a/EPPlus/Drawing/Vml/ExcelVmlDrawingPicture.cs b/EPPlus/Drawing/Vml/ExcelVmlDrawingPicture.cs
index d4b38ab..c46ab6b 100644
--- a/EPPlus/Drawing/Vml/ExcelVmlDrawingPicture.cs
+++ b/EPPlus/Drawing/Vml/ExcelVmlDrawingPicture.cs
@@ -35,6 +35,7 @@
 using System.Xml;
 using System.Globalization;
 using System.Drawing;
+using IronSoftware.Drawing;
 
 
 namespace OfficeOpenXml.Drawing.Vml
@@ -133,7 +134,7 @@
         /// <summary>
         /// The image
         /// </summary>
-        public Image Image
+        public AnyBitmap Image
         {
             get
             {
@@ -141,7 +142,7 @@
                 if (pck.PartExists(ImageUri))
                 {
                     var part = pck.GetPart(ImageUri);
-                    return Image.FromStream(part.GetStream());
+                    return AnyBitmap.FromStream(part.GetStream());
                 }
                 else
                 {
diff --git a/EPPlus/EPPlusSDK.csproj b/EPPlus/EPPlusSDK.csproj
index 49a58ac..eaa1e43 100644
--- a/EPPlus/EPPlusSDK.csproj
+++ b/EPPlus/EPPlusSDK.csproj
@@ -14,10 +14,12 @@
     <Reference Include="System.Web" />
   </ItemGroup>
   <ItemGroup>
+    <PackageReference Include="IronSoftware.System.Drawing" Version="2024.3.2" />
     <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
     <PackageReference Include="System.CodeDom" Version="5.0.0" />
-    <PackageReference Include="System.Drawing.Common" Version="5.0.3" />
+    <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
     <PackageReference Include="System.Security.Cryptography.Pkcs" Version="5.0.1" />
     <PackageReference Include="System.Security.Permissions" Version="5.0.0" />
+    <PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
   </ItemGroup>
 </Project>
diff --git a/EPPlus/ExcelWorksheet.cs b/EPPlus/ExcelWorksheet.cs
index c194e88..97c5e58 100644
--- a/EPPlus/ExcelWorksheet.cs
+++ b/EPPlus/ExcelWorksheet.cs
@@ -50,10 +50,10 @@
 using OfficeOpenXml.DataValidation;
 using OfficeOpenXml.Table.PivotTable;
 using System.ComponentModel;
-using System.Drawing;
 using OfficeOpenXml.ConditionalFormatting;
 using OfficeOpenXml.Utils;
 using Ionic.Zip;
+using IronSoftware.Drawing;
 using OfficeOpenXml.FormulaParsing.LexicalAnalysis;
 using OfficeOpenXml.FormulaParsing;
 using OfficeOpenXml.Packaging.Ionic.Zip;
diff --git a/EPPlus/ExcelWorksheets.cs b/EPPlus/ExcelWorksheets.cs
index 14ba636..ef13eaa 100644
--- a/EPPlus/ExcelWorksheets.cs
+++ b/EPPlus/ExcelWorksheets.cs
@@ -4,7 +4,7 @@
  * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
  * See http://www.codeplex.com/EPPlus for details.
  *
- * Copyright (C) 2011  Jan Källman
+ * Copyright (C) 2011  Jan K�llman
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,8 +26,8 @@
  * 
  * Author							Change						Date
  * ******************************************************************************
- * Jan Källman		    Initial Release		       2009-10-01
- * Jan Källman		    License changed GPL-->LGPL 2011-12-27
+ * Jan K�llman		    Initial Release		       2009-10-01
+ * Jan K�llman		    License changed GPL-->LGPL 2011-12-27
  *******************************************************************************/
 using System;
 using System.Collections;
@@ -693,7 +693,7 @@
                         if(!workSheet.Workbook._package.Package.PartExists(uri))
                         {
                             var picPart = workSheet.Workbook._package.Package.CreatePart(uri, pic.ContentType, CompressionLevel.None);
-                            pic.Image.Save(picPart.GetStream(FileMode.Create, FileAccess.Write), pic.ImageFormat);
+                            pic.Image.ExportStream(picPart.GetStream(FileMode.Create, FileAccess.Write), pic.ImageFormat);
                         }
                         
                         var rel = part.CreateRelationship(UriHelper.GetRelativeUri(workSheet.WorksheetUri, uri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/image");
diff --git a/NetCoreTests/NetCoreTests.csproj b/NetCoreTests/NetCoreTests.csproj
index 95aa3fb..ce61958 100644
--- a/NetCoreTests/NetCoreTests.csproj
+++ b/NetCoreTests/NetCoreTests.csproj
@@ -10,7 +10,7 @@
     <PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
     <PackageReference Include="Microsoft.NET.Test.SDK" Version="17.1.0"/>
     <PackageReference Include="System.Net.Http" Version="4.3.4"/>
-    <PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
+    <PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
     <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1"/>
 
     <ProjectReference Include="..\EPPlus\EPPlusSDK.csproj" />
diff --git a/NetFrameworkTests/NetFrameworkTests.csproj b/NetFrameworkTests/NetFrameworkTests.csproj
index 242fcf5..0750c60 100644
--- a/NetFrameworkTests/NetFrameworkTests.csproj
+++ b/NetFrameworkTests/NetFrameworkTests.csproj
@@ -9,7 +9,7 @@
     <PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
     <PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
     <PackageReference Include="Microsoft.NET.Test.SDK" Version="17.1.0"/>
-    <PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
+    <PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
 
     <ProjectReference Include="..\EPPlus\EPPlusSDK.csproj" />