The simple version of my problem is that I need to get the color of a pixel in an image when a user clicks on it. As I understand, there is no function for this in Javascript. I will now provide a more detailed explanantion of my problem and attempted solutions in hopes that a brilliant person will see a clever and simple way to solve my problem…
I have a png in an html image object. Some areas of the png have transparent background. When the user clicks on the png, I need to use javascript to determinine whether or not they clicked where ther is no background. (I must use client side code to do this and I want to use something that is supported everywhere, so I am using javascript) (I am not using flash for various reasons).
As I understand, I cannot get any information about the png at a particular pixel directly. So I have created a text file of 1s and 0s for the image (each number represents a pixel: 0 if clicked where the background is transparant, and 1 otherwise).
In a code behind file a create a global variable and read the entire text file of 1s and 0s into it. I can then access this variable in the javascript. Now depending on where the user clicks, I can tell whether they clicked on the transparent background or not.
This works great, except that it is very slow to get the page going. Transfering the text file into a string variable (the text file can have several million characters) takes a long time.
So I had the idea that I could compress the text files of 1’s and 0’s into ascii, and then convert it back from ascii to binary string on the other side (javascript). This would decrease the string length being sent to the clients browser by 7 or 8 times I think. I am having some issues doing this, and I keep thinking there must be a better way about all this!
So, perhaps there is a better way to compress a string, send it to the client, and then extract it?
Or perhaps there is a easier way to figure out the rgb, brightness etc. of a pixel that a client clicks on?
Or perhaps there is something I have completely overlooked that would solve my problem and simultaneously make me look really stupid, which I totally dont mind as long as it solves my problem!
Thanks very much to all that read this and try to help!
Sam