Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing backgroundColor on the fly #133

Closed
khawye opened this issue Nov 19, 2015 · 4 comments
Closed

changing backgroundColor on the fly #133

khawye opened this issue Nov 19, 2015 · 4 comments

Comments

@khawye
Copy link

khawye commented Nov 19, 2015

Hey,

on initialize I have the signing pad (canvas) set to a specific color but I would like to save it on a transparent or white background. I already used the linked prototype removeBlanks function to capture just the signature but the bg still rgb(255,243,204) i try to change it via
signaturePad.backgroundColor = rgb(255, 255, 255); but it seems like upon signing stroke, the base64 image has already been registered.

Any ideas?

@szimek
Copy link
Owner

szimek commented Nov 19, 2015

Maybe simply swapping colors before sending it to the server would work? You could get raw image data using CanvasContext2D#getImageData(), iterate over every pixel and swap visible background color (8 bit integer) to the desired one. Save modified image data to an offscreen canvas and read it back using Canvas#toDataURL(). Might work :)

BTW. The background color is applied when canvas is cleared, so only on initialize or when you call SignaturePad#clear() explicitly.

@khawye
Copy link
Author

khawye commented Nov 19, 2015

@szimek thanks for the response. I was looking to piggy back on the removeBlanks function for this too. I just have to figure out how to tell if it is a background pixel vs a signature pixel.

Also is there a way to get the json array representation of the signature
i.e. {lx : 20, ly : 34, mx : 20, my : 34}

@szimek
Copy link
Owner

szimek commented Nov 19, 2015

Unfortunately not at the moment. Only the last 4 points are kept in memory, so there's no way to access all points. It might change in the future, but there are some others issues (mainly related to retina/non-retina screens) with higher priority.

You could quite easily change the library to store all points if you really need this data, though.

@szimek
Copy link
Owner

szimek commented Nov 21, 2015

@khawye If you have any more questions, please reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants