2

I am able to draw a signature on my canvas. Now after that I want to save this signature as an image which can be used later.

I am unable to implement an onClicklistener on this canvas. Also I am unclear as to how this signature can be stored as an image. Please suggest?

theblang
  • 10,215
  • 9
  • 69
  • 120
NickHalden
  • 267
  • 1
  • 3
  • 13

2 Answers2

2

Try this:

Bitmap bmp = Bitmap.createBitmap(...);
Canvas can = new Canvas(bmp);

When you change your canvas, bitmap bmp will change too. Canvas is only raference to Bitmap canvas, and you have no need to save canvas. Save only Bitmap (bmp).

Alexander Mikhaylov
  • 1,790
  • 1
  • 13
  • 23
0

To save the canvas drawing as an image, you need to convert it to a data url using the toDataURL method. Once you have the data url, you can use it to set the source of an image element so the user can right click and download the image.:

// save canvas image as data url (png format by default)
var dataURL = canvas.toDataURL();

// set canvasImg image src to dataURL
// so it can be saved as an image
document.getElementById("canvasImg").src = dataURL;

Reference: http://www.html5canvastutorials.com/advanced/html5-canvas-save-drawing-as-an-image/

Eric Rowell
  • 5,191
  • 23
  • 22