I'm currently building a HTML5 web app/Phonegap native app and I can't seem to figure out how to save my canvas as an image with canvas.toDataURL()
. Can somebody help me out?
Here's the code, what's wrong with it?
//My canvas was named "canvasSignature"
JavaScript:
function putImage()
{
var canvas1 = document.getElementById("canvasSignature");
if (canvas1.getContext) {
var ctx = canvas1.getContext("2d");
var myImage = canvas1.toDataURL("image/png");
}
var imageElement = document.getElementById("MyPix");
imageElement.src = myImage;
}
HTML5:
<div id="createPNGButton">
<button onclick="putImage()">Save as Image</button>
</div>
.toDataURL()
, then use window.location to point the browser toappname://[data url]
. On the app end, the UIWebView has a delegate method that says whether or not it should load a page. I listen forappname://
and break it down when it comes in, deny the page load and capture the data url in a native string... how familiar are you with actual iOS/Objective C code?