简体   繁体   English

如何在 Javascript 中将 PNG 转换为 SVG

[英]How to convert PNG to SVG in Javascript

I want to convert png, base64 to SVG我想将 png,base64 转换为 SVG

therefore I can delete a specific part of the image which is only possible in SVG.因此我可以删除图像的特定部分,这只能在 SVG 中实现。

Basically I want to achieve erase functionality by deleting a path from SVG基本上我想通过从 SVG 中删除路径来实现擦除功能

I've tried this我试过这个

var canvas = document.getElementById('canvas');
var svg = canvas.toDataURL('svg', 1.0);

But I guess there is no argument for SVG on canvas.但我想 canvas 上的 SVG 没有任何论据。

Do we have any method to convert?我们有什么方法可以转换吗?

PNG is a raster format... you end up with a grid of pixels. PNG是一种光栅格式......你最终会得到一个像素网格。 SVG is a vector format... effectively commands to draw shapes and paths with certain styles. SVG 是一种矢量格式...有效地命令以某些 styles 绘制形状和路径。

They are inherently incompatible.它们本质上是不相容的。 You cannot convert from a PNG to an SVG.您无法从 PNG 转换为 SVG。 (Well, not usefully. I suppose you could draw a rectangle for each pixel, but why would you? The size would be huge.) (嗯,没用。我想你可以为每个像素画一个矩形,但你为什么要这样做?尺寸会很大。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM