The call canvas.toDataUrl should be synchronous so your timeout would not be set until after the call had completed.
Have you observed asynchronous behavior? Sent from my iPhone On 2010-07-20, at 4:48 PM, Excell <[email protected]> wrote: > I am having some success in achieving what my aim was using simple > code. > But I have one question > > I have had to use a setTimeout to wait for the canvas.toDataURL() to > complete before saveing the data. > > This is not a great way to move forward as depending on the size of > the image will change the amount of time i would need to set. > > Is there anyway to know when canvas.toDataUrl() is complete > > maybe I am coding this wrong > > Hope that makes sense > > <sample code below> > function drawImage(img) { > var canvas = document.createElement("canvas"); > canvas.width = img.width; > canvas.height = img.height; > var ctx = canvas.getContext("2d"); > ctx.drawImage(img,0,0); > var dataURL = canvas.toDataURL(); > setTimeout(insert(dataURL),2000);//delay enough for the canvas to be > converted and save to local database > > //insert(dataURL); > //this.cacheImageData(img.src, dataURL); > } > > Thanks > > Roger[Excell] > > On Jul 16, 7:14 pm, Bill Humphries <[email protected]> wrote: >> On Jul 16, 2010, at 11:08 AM, Jesse MacFadyen wrote: >> >>> Here's how to get the data from an image. >>> http://blogs.nitobi.com/jesse/2009/09/24/image-caching-with-the-html5... >> >> Thanks, Jesse. That's much more succinct than my example. Bookmarkiing it. >> >> -- Bill Humphrieshttp://whump.com > > -- > You received this message because you are subscribed to the Google Groups > "iPhoneWebDev" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/iphonewebdev?hl=en. > -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
