I have html5 canvas imageData and want to save as vector image(esp or svg) on server. I have tried to use Magick.NET and SVG Rendering Engine libraries but could not found any way to convert this imageData into vector image format. Can you please share code for this purpose. Here is my code.
public static string UploadImage(string imageData, string userEmail, int quantity)
{
string completePath = @"~\user-images\file.svg";
byte[] byteArray = Convert.FromBase64String(imageData);
//How can i convert this byteArray into vector image array so that i can save it as vector image on spcified path?
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(completePath), FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
}
EDIT: I have learn from someone that once raster imageData is generated it can't be converted to vector image. So the question will be that how can I saved the html canvas as vector image on server without getting raster imageData.
So for now I have tried to use fabric library to generate SVG image by using .toSVG() fabric method. Here is code:
var fCanvas = new fabric.Image('c');
var imageurl = myCanvas.toDataURL("image/png"); // this is the origional html canvas that I used to draw images.
fabric.Image.fromURL(imageurl, function (img) {
img.scaleToWidth(fCanvas.width);
fCanvas.add(img);
fCanvas.renderAll();
}, { crossOrigin: 'anonymous' });
//fCanvas.deactivateAll().renderAll();
window.open('data:image/svg+xml;utf8,' + fCanvas.toSVG());
But in this case blank output generated. Can anybody please suggest where the problem is.