简体   繁体   English

Uint8ClampedArray图片转为jpg / png

[英]Uint8ClampedArray image to jpg/png

I have an image stored in a Uint8ClampedArray in my web page. 我的网页中有一个图像存储在Uint8ClampedArray中。 I'd like to save this image in a jpg/png file on my server. 我想将此图像保存在服务器上的jpg / png文件中。

I can access to the image executing this code: 我可以访问执行以下代码的图像:

canvas.putImageData(imgData,0,0);

// create a new img object
var image=new Image();
// set the img.src to the canvas data url
image.src=canvas.toDataURL();

Now in my image.src I have a very long string which represent the image. 现在在我的image.src中,我有一个很长的字符串来表示图像。

I have two question: 我有两个问题:

  • Do i need to use the canvas to get the img source or I can get it without using it? 我是否需要使用画布来获取img源,还是可以不使用它而获取它?
  • Is it possible to convert the image in a jpg/png file in the browser or I have to do the process in the server? 是否可以在浏览器中将图像转换为jpg / png文件,或者我必须在服务器中进行处理?

I'd like to better understand how this process works. 我想更好地了解此过程的工作原理。 Thanks for your help!! 谢谢你的帮助!!

Strictly speaking it's possible to do without canvas the hard way, by implementing your own JPEG encoder from scratch in JS/asm.js/WASM, but with canvas that's much easier. 严格来说,可以通过在JS / asm.js / WASM中从头开始实现自己的JPEG编码器来实现不使用画布的困难,但是使用画布要容易得多。

To get a JPEG the only change you need is to specify the type: toDataURL("image/jpeg") . 要获取JPEG,唯一需要做的更改就是指定类型: toDataURL("image/jpeg")

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

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