Hello,
We converted the following SVG file to DXF and PNG and it returns incorrect line crossing through the object.
The line is marked in this image from the resulting DXF file : AddedLineIssue.png (7.5 KB) and the conversion code is added below.
The SVG image and the resulting DXF and PNG has been attached as a zip file:
ResultingPNGAndDXF.zip (5.4 KB)
We are using Aspose.Imaging version 24.2.0 but we observed that the problem persists on the latest version 24.6.0 also.
Could you please help us in resolving this issue?
Thank you,
Victor
namespace Conversion
{
using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Svg;
using Aspose.Imaging.ImageOptions;
public static class ImageConverter
{
private static readonly float Ratio = 71.6f;
public static byte[] ConvertSvgToDxf(string svgInput, bool addBorder)
{
using (var stream = GenerateStreamFromString(svgInput))
{
using (var image = Image.Load(stream))
{
ImageOptionsBase exportOptions = new DxfOptions
{
TextAsLines = false,
ConvertTextBeziers = false
};
if (image is VectorImage)
{
using (VectorRasterizationOptions rasterizationOptions = new SvgRasterizationOptions())
{
rasterizationOptions.PageWidth = image.Width / Ratio;
rasterizationOptions.PageHeight = image.Height / Ratio;
rasterizationOptions.BackgroundColor = !addBorder ? Color.Empty : Color.LightGray;
exportOptions.VectorRasterizationOptions = rasterizationOptions;
}
}
using (MemoryStream outputStream = new MemoryStream())
{
image.Save(outputStream, exportOptions);
return outputStream.ToArray();
}
}
}
}
public static byte[] ConvertSvgToPng(string svgInput)
{
using var stream = GenerateStreamFromString(svgInput);
using var image = (SvgImage) Image.Load(stream);
var pngOptions = new PngOptions();
if (image != null)
{
var rasterizationOptions = new SvgRasterizationOptions
{
PageWidth = image.Width,
PageHeight = image.Height
};
pngOptions.VectorRasterizationOptions = rasterizationOptions;
}
using var outputStream = new MemoryStream();
image?.Save(outputStream, pngOptions);
return outputStream.ToArray();
}
private static Stream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
}
}