This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Extra content at the end of the document

Hello,

When I'm converting any kind of image to svg and when I open the image, I get the following error: "error on line 1 at column 4934196: Extra content at the end of the document"

code snippet:

private static byte[] ConvertToSvg(byte[] bytes)
{
	using (var imageReader = ImageReader.Create(new MemoryStream(bytes)))
	using (var bitmap = imageReader.Frames[0].GetBitmap())
	using (var exportedImageStream = new MemoryStream())
	{
		bitmap.Save(exportedImageStream, new SvgSettings());

		return exportedImageStream.GetBuffer();
	}
}


I'm using Graphics Mill v9.0.21

All my best,
Bruno

attach #1306
Hey,

We confirm the problem (Aurigma Bug #0022944) and will fix it shortly.

I will keep you informed of the status.
Here is a documentation of the MemoryStream.GetBuffer method:

https://msdn.microsoft.com/en-us/library/system.io.memorystream.getbuffer

MSDN
Note that the buffer contains allocated bytes which might be unused. For example, if the string "test" is written into the MemoryStream object, the length of the buffer returned from GetBuffer is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the ToArray method; however, ToArray creates a copy of the data in memory.


That's why you get null values in the SVG file and should use the MemoryStream.GetArray method to fix the problem:

Corrected:

private static byte[] ConvertToSvg(byte[] bytes)
{
	using (var imageReader = ImageReader.Create(new MemoryStream(bytes)))
	using (var bitmap = imageReader.Frames[0].GetBitmap())
	using (var exportedImageStream = new MemoryStream())
	{
		bitmap.Save(exportedImageStream, new SvgSettings());

		return exportedImageStream.ToArray();
	}
}