问题
I am a newbie using webgl implementation as a dependent module for my project. I am trying to use .toDataURL() function using node-webgl wrapper at server side. But I get an error station .toDataURL() is undefined. For more detail, please have a look at this link: canvas.toDataURL() is not a function - error node-webGL wrapper
Well the current post is definitely not a duplicate. In the post(earlier link shared) I am trying to find an alternative way to access the data of canvas. The goal of this current post is to implement the .toDataURL() function. I am novice in these webgl. Could you please share some links or procedure on how to implement this small function. or Could I access the same function of browser implementation(copy it here), where can I get that?
Any suggestions will definitely be helpful.
Thank You.
回答1:
A data URI consists of:
data:[<media type>][;base64],<data>
All you need to do is concatenate:
- a string
"data:"
- a media type - e.g.
"image/jpeg"
- a string
";base64,"
- Base64 representation of your data
For more info see:
- https://en.wikipedia.org/wiki/Data_URI_scheme
- https://en.wikipedia.org/wiki/Base64
There are several modules on npm
that can help you generate Base64:
- https://www.npmjs.com/search?q=base64
This is basically everything that you need to know to implement toDataURL()
function.
来源:https://stackoverflow.com/questions/39663059/how-to-implement-todataurl-function-in-node-js-server