SVG
SVG copied to clipboard
SVG to Bitmap gives different size byte[] if run as x86 or x64
The following code includes sample code and a sample SVG where the stream size and bytes are different if running as x86 or x64.
byte[] test is different between 32/64 bit byte[] bytes is also different between 32/64 bit string hashAsHex does not match between between 32/64 bit
Is this a bug or is there a way to get exactly the same result if running as either x86 or x64?
using Svg;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string svgImage = GetExampleSVG();
string svgString = "<svg" + svgImage.Split(new string[] { "<svg" }, StringSplitOptions.None)[1];
var svgDocument = SvgDocument.FromSvg<SvgDocument>(svgString);
Bitmap image = svgDocument.Draw();
//Alt byte size test
ImageConverter converter = new ImageConverter();
byte[] test = (byte[])converter.ConvertTo(image, typeof(byte[]));
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] bytes = stream.ToArray();
var sha256 = new System.Security.Cryptography.SHA256Managed();
byte[] hash = sha256.ComputeHash(bytes);
string hashAsHex = BitConverter.ToString(hash).Replace("-", "").ToLower();
Debug.WriteLine(hashAsHex);
//<ItemGroup>
//<Reference Include="Svg, Version=2.2.1.39233, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
//<HintPath>..\packages\Svg.2.3.0\lib\net35\Svg.dll</HintPath>
//</Reference>
//<Reference Include="System" />
//<Reference Include="System.Core" />
//<Reference Include="System.Drawing" />
//<Reference Include="System.Xml.Linq" />
//<Reference Include="System.Data.DataSetExtensions" />
//<Reference Include="Microsoft.CSharp" />
//<Reference Include="System.Data" />
//<Reference Include="System.Net.Http" />
//<Reference Include="System.Xml" />
//</ItemGroup>
}
static string GetExampleSVG()
{
return @"<?xml version=""1.0"" encoding=""UTF-8""?>
<svg xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"" width=""97.59pt"" height=""70.53pt"" viewBox=""0 0 97.59 70.53"" version=""1.1"">
<defs>
<clipPath id=""clip1"">
<path d=""M 0 70.53125 L 97.589844 70.53125 L 97.589844 0.03125 L 0 0.03125 L 0 70.53125 Z M 0 70.53125 ""/>
</clipPath>
</defs>
<g id=""surface0"">
<g clip-path=""url(#clip1)"" clip-rule=""nonzero"">
<path style="" stroke:none;fill-rule:nonzero;fill:rgb(3.105211%,58.818952%,38.753338%);fill-opacity:1;"" d=""M 13.121094 11.28125 C 13.121094 11.28125 18.203125 14.53125 19.703125 29.863281 C 19.703125 29.863281 19.703125 44.863281 19.703125 70.03125 L 59.996094 70.03125 L 59.996094 29.695312 C 59.996094 29.695312 61.789062 14.695312 66.746094 11.28125 L 49.746094 4.53125 L 49.746094 0.53125 C 49.746094 0.53125 39.855469 -0.304688 39.855469 6.53125 C 39.855469 6.53125 40.871094 0.53125 30.121094 0.53125 L 30.121094 4.53125 L 13.121094 11.28125 ""/>
<path style=""fill:none;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(13.730068%,12.159915%,12.54902%);stroke-opacity:1;stroke-miterlimit:4;"" d=""M 131.210938 592.4875 C 131.210938 592.4875 182.03125 559.9875 197.03125 406.667187 C 197.03125 406.667187 197.03125 256.667187 197.03125 4.9875 L 599.960938 4.9875 L 599.960938 408.346875 C 599.960938 408.346875 617.890625 558.346875 667.460938 592.4875 L 497.460938 659.9875 L 497.460938 699.9875 C 497.460938 699.9875 398.554688 708.346875 398.554688 639.9875 C 398.554688 639.9875 408.710938 699.9875 301.210938 699.9875 L 301.210938 659.9875 L 131.210938 592.4875 Z M 131.210938 592.4875 "" transform=""matrix(0.1,0,0,-0.1,0,70.53)""/>
<path style="" stroke:none;fill-rule:nonzero;fill:rgb(3.105211%,58.818952%,38.753338%);fill-opacity:1;"" d=""M 12.601562 69.570312 C 13.351562 68.070312 19.351562 35.820312 19.351562 35.820312 C 19.851562 24.320312 16.351562 12.570312 12.851562 11.570312 L 0.601562 67.570312 L 12.601562 69.570312 ""/>
<path style=""fill:none;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(13.730068%,12.159915%,12.54902%);stroke-opacity:1;stroke-miterlimit:4;"" d=""M 126.015625 9.596875 C 133.515625 24.596875 193.515625 347.096875 193.515625 347.096875 C 198.515625 462.096875 163.515625 579.596875 128.515625 589.596875 L 6.015625 29.596875 L 126.015625 9.596875 Z M 126.015625 9.596875 "" transform=""matrix(0.1,0,0,-0.1,0,70.53)""/>
<path style="" stroke:none;fill-rule:nonzero;fill:rgb(3.105211%,58.818952%,38.753338%);fill-opacity:1;"" d=""M 78.601562 67.820312 L 66.851562 11.570312 C 63.351562 12.570312 59.601562 24.570312 60.101562 36.070312 C 60.101562 36.070312 65.851562 68.320312 66.601562 69.820312 L 78.601562 67.820312 ""/>
<path style=""fill:none;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(13.730068%,12.159915%,12.54902%);stroke-opacity:1;stroke-miterlimit:4;"" d=""M 786.015625 27.096875 L 668.515625 589.596875 C 633.515625 579.596875 596.015625 459.596875 601.015625 344.596875 C 601.015625 344.596875 658.515625 22.096875 666.015625 7.096875 L 786.015625 27.096875 Z M 786.015625 27.096875 "" transform=""matrix(0.1,0,0,-0.1,0,70.53)""/>
<path style=""fill-rule:nonzero;fill:rgb(100%,95.410086%,10.000763%);fill-opacity:1;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(13.730068%,12.159915%,12.54902%);stroke-opacity:1;stroke-miterlimit:4;"" d=""M 780.664062 440.495312 C 820.390625 284.870312 1004.335938 332.448437 965.546875 484.440625 "" transform=""matrix(0.1,0,0,-0.1,0,70.53)""/>
<path style="" stroke:none;fill-rule:nonzero;fill:rgb(100%,95.410086%,10.000763%);fill-opacity:1;"" d=""M 32.597656 69.53125 L 46.285156 69.53125 L 46.285156 6.53125 L 32.597656 6.53125 L 32.597656 69.53125 Z M 32.597656 69.53125 ""/>
<path style="" stroke:none;fill-rule:nonzero;fill:rgb(100%,95.410086%,10.000763%);fill-opacity:1;"" d=""M 88.828125 30.097656 C 94.386719 28.679688 97.742188 23.023438 96.324219 17.46875 C 94.90625 11.910156 89.25 8.554688 83.691406 9.972656 C 78.132812 11.390625 74.777344 17.046875 76.195312 22.601562 C 77.613281 28.160156 83.269531 31.515625 88.828125 30.097656 ""/>
<path style=""fill:none;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(13.730068%,12.159915%,12.54902%);stroke-opacity:1;stroke-miterlimit:4;"" d=""M 888.28125 404.323437 C 943.867188 418.503125 977.421875 475.065625 963.242188 530.6125 C 949.0625 586.198437 892.5 619.753125 836.914062 605.573437 C 781.328125 591.39375 747.773438 534.83125 761.953125 479.284375 C 776.132812 423.698437 832.695312 390.14375 888.28125 404.323437 Z M 888.28125 404.323437 "" transform=""matrix(0.1,0,0,-0.1,0,70.53)""/>
</g>
</g>
</svg>
";
}
}
}
Used Versions
I've tested on versions SVG 2.3 and 3.1.1. Occurs on .NET4.6+ and .NET5.0
This library uses via Graphics class. There may be a difference between x86 and x64 in Rendering. (Especially in binary.)
Please attach images output in each environment.