2011/9/11 Jane <[email protected]>: > Hi, I am a newbie on JS and was trying to do alpha blending without a > full success for a couple of days. The code is here: > > var img1 = document.getElementById('foreground'); > var img2 = document.getElementById('background'); > var canvas = document.getElementById("result"); > var context = canvas.getContext("2d"); > var width = img1.width; > var height = img1.height; > canvas.width = width; > canvas.height = height; > var alpha = 0.5; > var pixels = 4 * width * height; > // get foreground image data > context.drawImage(img1, 0, 0); > var image1 = context.getImageData(0, 0, width, height); > var imageData1 = image1.data; > // get background image data > context.drawImage(img2, 0, 0); > var image2 = context.getImageData(0, 0, width, height); > var imageData2 = image2.data; > // alpha blending > while (pixels--) { > imageData1[pixels] = imageData1[pixels] * alpha + > imageData2[pixels] * alpha; > } > // send the result to canvas > image1.data = imageData1; > context.putImageData(image1, 0, 0); > > > I found that Safari displays blended image just fine. However in > Chrome, the line on context.getImageData triggered the following error > message: > > 58 Uncaught Error: SECURITY_ERR: DOM Exception 18 > > Thank you very much in advance, > > Jane
If you would have checked for the error, you would know, that there are a couple of issues that can trigger the error. http://stackoverflow.com/questions/2704929/uncaught-error-security-err-dom-exception-18 Mainly the issue could be that one of the images is on a different domain then the page, or on your machine, not coming from a domain. -- Poetro -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
