Skip to content

Remove System.Drawing #452

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions src/EPPlus/EPPlus/Compatibility/ImageCompat.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
using OfficeOpenXml.Utils;
using System.Drawing;
using System.Drawing.Imaging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;

namespace OfficeOpenXml.Compatibility
{
internal class ImageCompat
{
internal static byte[] GetImageAsByteArray(Image image)
internal static byte[] GetImageAsByteArray(Image image, IImageFormat format)
{
var ms = RecyclableMemoryStream.GetStream();
if (image.RawFormat.Guid == ImageFormat.Gif.Guid)
using (var ms = RecyclableMemoryStream.GetStream())
{
image.Save(ms, ImageFormat.Gif);
image.Save(ms, format);
return ms.ToArray();
}
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);
}
else
{
image.Save(ms, ImageFormat.Jpeg);
}

return ms.ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ******************************************************************************
* Eyal Seagull Conditional Formatting Adaption 2012-04-03
*******************************************************************************/
using System.Drawing;
using SixLabors.ImageSharp;

namespace OfficeOpenXml.ConditionalFormatting.Contracts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Eyal Seagull Conditional Formatting 2012-04-03
*******************************************************************************/
using OfficeOpenXml.ConditionalFormatting.Contracts;
using System.Drawing;
using SixLabors.ImageSharp;

namespace OfficeOpenXml.ConditionalFormatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Xml;

namespace OfficeOpenXml.ConditionalFormatting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
*******************************************************************************/
using OfficeOpenXml.Utils;
using System;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Xml;
using Magicodes.IE.EPPlus.SixLabors;

namespace OfficeOpenXml.ConditionalFormatting
{
Expand Down Expand Up @@ -423,7 +424,7 @@ public Color Color
CreateNodeByOrdem(
eExcelConditionalFormattingValueObjectNodeType.Color,
ExcelConditionalFormattingConstants.Paths.RgbAttribute,
value.ToArgb().ToString("x"));
value.ToArgbHex());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ******************************************************************************
* Eyal Seagull Conditional Formatting Adaption 2012-04-03
*******************************************************************************/
using System.Drawing;
using SixLabors.ImageSharp;

namespace OfficeOpenXml.ConditionalFormatting
{
Expand Down Expand Up @@ -272,9 +272,9 @@ internal class TimePeriods
#region Colors
internal class Colors
{
internal static readonly Color CfvoLowValue = Color.FromArgb(0xFF, 0xF8, 0x69, 0x6B);
internal static readonly Color CfvoMiddleValue = Color.FromArgb(0xFF, 0xFF, 0xEB, 0x84);
internal static readonly Color CfvoHighValue = Color.FromArgb(0xFF, 0x63, 0xBE, 0x7B);
internal static readonly Color CfvoLowValue = Color.FromRgba(0xF8, 0x69, 0x6B, 0xFF);
internal static readonly Color CfvoMiddleValue = Color.FromRgba(0xFF, 0xEB, 0x84, 0xFF);
internal static readonly Color CfvoHighValue = Color.FromRgba(0x63, 0xBE, 0x7B, 0xFF);
}
#endregion Colors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
*******************************************************************************/
using OfficeOpenXml.Utils;
using System;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using SixLabors.ImageSharp.PixelFormats;

namespace OfficeOpenXml.ConditionalFormatting
{
Expand Down Expand Up @@ -77,7 +78,8 @@ public static Color ConvertFromColorCode(
{
try
{
return Color.FromArgb(Int32.Parse(colorCode.Replace("#", ""), NumberStyles.HexNumber));
var rgba32 = new Rgba32(uint.Parse(colorCode.Replace("#", ""), NumberStyles.HexNumber));
return Color.FromRgba(rgba32.R, rgba32.G, rgba32.B, rgba32.A);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*******************************************************************************/
using OfficeOpenXml.Utils;
using System;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Xml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*******************************************************************************/
using OfficeOpenXml.ConditionalFormatting.Contracts;
using OfficeOpenXml.Utils;
using SixLabors.ImageSharp;

namespace OfficeOpenXml.ConditionalFormatting
{
Expand Down Expand Up @@ -514,7 +515,7 @@ public IExcelConditionalFormattingFiveIconSet AddFiveIconSet(eExcelconditionalFo
/// </summary>
/// <param name="Color">The color of the databar</param>
/// <returns></returns>
public IExcelConditionalFormattingDataBarGroup AddDatabar(System.Drawing.Color Color)
public IExcelConditionalFormattingDataBarGroup AddDatabar(Color Color)
{
var rule = (IExcelConditionalFormattingDataBarGroup)(_worksheet.ConditionalFormatting.AddRule(
eExcelConditionalFormattingRuleType.DataBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
*******************************************************************************/
using OfficeOpenXml.ConditionalFormatting.Contracts;
using System;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Xml;
using Magicodes.IE.EPPlus.SixLabors;
using SixLabors.ImageSharp.PixelFormats;

namespace OfficeOpenXml.ConditionalFormatting
{
/// <summary>
Expand Down Expand Up @@ -222,13 +225,14 @@ public Color Color
var rgb = GetXmlNodeString(_colorPath);
if (!string.IsNullOrEmpty(rgb))
{
return Color.FromArgb(int.Parse(rgb, NumberStyles.HexNumber));
var argb32 = new Argb32(Convert.ToUInt32(rgb, 16));
return Color.FromRgba(argb32.R, argb32.G, argb32.B, argb32.A);
}
return Color.White;
}
set
{
SetXmlNodeString(_colorPath, value.ToArgb().ToString("X"));
SetXmlNodeString(_colorPath, value.ToArgbHex());
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/EPPlus/EPPlus/Drawing/Chart/ExcelLineChartSerie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
* Jan Källman License changed GPL-->LGPL 2011-12-16
*******************************************************************************/
using System;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Xml;
using Magicodes.IE.EPPlus.SixLabors;
using SixLabors.ImageSharp.PixelFormats;

namespace OfficeOpenXml.Drawing.Chart
{
Expand Down Expand Up @@ -127,12 +129,12 @@ public Color LineColor
}
else
{
return Color.FromArgb(Convert.ToInt32(color, 16));
return Color.ParseHex(color);
}
}
set
{
SetXmlNodeString(LINECOLOR_PATH, value.ToArgb().ToString("X").Substring(2), true);
SetXmlNodeString(LINECOLOR_PATH, value.ToArgbHex().Substring(2), true);
}
}
string MARKERSIZE_PATH = "c:marker/c:size/@val";
Expand Down Expand Up @@ -217,12 +219,12 @@ public Color MarkerLineColor
}
else
{
return Color.FromArgb(Convert.ToInt32(color, 16));
return Color.ParseHex(color);
}
}
set
{
SetXmlNodeString(MARKERLINECOLOR_PATH, value.ToArgb().ToString("X").Substring(2), true);
SetXmlNodeString(MARKERLINECOLOR_PATH, value.ToArgbHex()/*.Substring(2)*/, true);
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/EPPlus/EPPlus/Drawing/Chart/ExcelScatterChartSerie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Drawing;
using SixLabors.ImageSharp;
using System.Globalization;
using System.Xml;
using Magicodes.IE.EPPlus.SixLabors;
using SixLabors.ImageSharp.PixelFormats;

namespace OfficeOpenXml.Drawing.Chart
{
Expand Down Expand Up @@ -150,18 +152,18 @@ public Color LineColor
}
else
{
Color c = Color.FromArgb(Convert.ToInt32(color, 16));
Color c = Color.ParseHex(color);
int a = getAlphaChannel(LINECOLOR_PATH);
if (a != 255)
{
c = Color.FromArgb(a, c);
c = c.WithAlpha(a);
}
return c;
}
}
set
{
SetXmlNodeString(LINECOLOR_PATH, value.ToArgb().ToString("X8").Substring(2), true);
SetXmlNodeString(LINECOLOR_PATH, value.ToArgbHex()/*.Substring(2)*/, true);
setAlphaChannel(value, LINECOLOR_PATH);
}
}
Expand Down Expand Up @@ -218,18 +220,19 @@ public Color MarkerColor
}
else
{
Color c = Color.FromArgb(Convert.ToInt32(color, 16));
var argb32 = new Argb32(Convert.ToUInt32(color, 16));
Color c = Color.FromRgba(argb32.R, argb32.G, argb32.B, argb32.A);
int a = getAlphaChannel(MARKERCOLOR_PATH);
if (a != 255)
{
c = Color.FromArgb(a, c);
c = c.WithAlpha(a);
}
return c;
}
}
set
{
SetXmlNodeString(MARKERCOLOR_PATH, value.ToArgb().ToString("X8").Substring(2), true); //.Substring(2) => cut alpha value
SetXmlNodeString(MARKERCOLOR_PATH, value.ToArgbHex()/*.Substring(2)*/, true); //.Substring(2) => cut alpha value
setAlphaChannel(value, MARKERCOLOR_PATH);
}
}
Expand Down Expand Up @@ -282,18 +285,19 @@ public Color MarkerLineColor
}
else
{
Color c = Color.FromArgb(Convert.ToInt32(color, 16));
var argb32 = new Argb32(Convert.ToUInt32(color, 16));
Color c = Color.FromRgba(argb32.R, argb32.G, argb32.B, argb32.A);
int a = getAlphaChannel(MARKERLINECOLOR_PATH);
if (a != 255)
{
c = Color.FromArgb(a, c);
c = c.WithAlpha(a);
}
return c;
}
}
set
{
SetXmlNodeString(MARKERLINECOLOR_PATH, value.ToArgb().ToString("X8").Substring(2), true);
SetXmlNodeString(MARKERLINECOLOR_PATH, value.ToArgbHex()/*.Substring(2)*/, true);
setAlphaChannel(value, MARKERLINECOLOR_PATH);
}
}
Expand All @@ -311,14 +315,15 @@ public Color MarkerLineColor
/// </remarks>
private void setAlphaChannel(Color c, string xPath)
{
var argb32 = c.ToPixel<Argb32>();
//check 4 Alpha-values
if (c.A != 255)
if (argb32.A != 255)
{ //opaque color => alpha == 255 //source: https://msdn.microsoft.com/en-us/library/1hstcth9%28v=vs.110%29.aspx
//check path
string s = xPath4Alpha(xPath);
if (s.Length > 0)
{
string alpha = ((c.A == 0) ? 0 : (100 - c.A) * 1000).ToString(); //note: excel writes 100% transparency (alpha=0) as "0" and not as "100000"
string alpha = ((argb32.A == 0) ? 0 : (100 - argb32.A) * 1000).ToString(); //note: excel writes 100% transparency (alpha=0) as "0" and not as "100000"
SetXmlNodeString(s, alpha, true);
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/EPPlus/EPPlus/Drawing/ExcelDrawingFill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
* Jan Källman License changed GPL-->LGPL 2011-12-16
*******************************************************************************/
using System;
using System.Drawing;
using System.Globalization;
using SixLabors.ImageSharp;
using System.Xml;
using Magicodes.IE.EPPlus.SixLabors;
using SixLabors.ImageSharp.PixelFormats;

namespace OfficeOpenXml.Drawing
{
Expand Down Expand Up @@ -152,11 +155,12 @@ public Color Color
string col = GetXmlNodeString(_fillPath + ColorPath);
if (col == "")
{
return Color.FromArgb(79, 129, 189);
return Color.FromRgb(79, 129, 189);
}
else
{
return Color.FromArgb(int.Parse(col, System.Globalization.NumberStyles.AllowHexSpecifier));
var argb32 = new Argb32(uint.Parse(col, NumberStyles.AllowHexSpecifier));
return Color.FromRgba(argb32.R, argb32.G, argb32.B, argb32.A);
}
}
set
Expand All @@ -171,7 +175,7 @@ public Color Color
}
CreateNode(_fillPath, false);
//fix ArgumentOutOfRangeException for Fill colors for solid fills with an alpha-value from zero (100% transparency)
SetXmlNodeString(_fillPath + ColorPath, value.ToArgb().ToString("X8").Substring(2));
SetXmlNodeString(_fillPath + ColorPath, value.ToArgbHex());
}
}
const string alphaPath = "/a:solidFill/a:srgbClr/a:alpha/@val";
Expand All @@ -189,7 +193,7 @@ public int Transparancy
if (_fillTypeNode == null)
{
_style = eFillStyle.SolidFill;
Color = Color.FromArgb(79, 129, 189); //Set a Default color
Color = Color.FromRgb(79, 129, 189); //Set a Default color
}
else if (_style != eFillStyle.SolidFill)
{
Expand Down
Loading