I have a finger drawing application, and I want my users to be able to save what they are drawing and come back later and continue drawing.
What is an easier way to do this?
One way to do this:
Save the contents of the canvas as a base64 encoded PNG image by calling canvas.toDataURL () and save the encoded string on the localStorage page .
If you want to restore the canvas, you must create an image, set src as the value previously saved locally, and then draw this image on the canvas.
, , .
HTML:
<input type="button" id="save" value="Save to PNG">
script:
document.getElementById('save').onclick = function () { window.location = document.getElementById("canvas").toDataURL('image/png'); };
Canvases drawImage . / ( , ) , .
you can use js. It has a method that helps serialize JSON, and then you can save that JSON to the database. documentation
Source: https://habr.com/ru/post/1760586/More articles:Stop method, - c ++Многопоточное приложение ptrace - linuxIn Spring, how do you get the current user whose credentials are not part of the current HTTP request? - javaPython module search path - pythonCode analysis is not performed when binding the project to assembly obfuscation - .netWhat is OpenMP? - c ++Метод расширения для ведения журнала. Хорошая идея? - stringКак сохранить измененное дерево на диск с помощью XML Twig - perlHow to change management themes in a Win32 API application? - c ++Run an unmanaged class from .NET. - .netAll Articles