getimagedata

html5 getImageData then putImageData results in fading image

≡放荡痞女 提交于 2019-12-06 14:57:40
I'm very new to Html5 and I was wondering if someone could shed some light on this: <script type="text/javascript"> window.onload = function () { var canvas = document.getElementById('canvas'); //682 x 111 pixel canvas var context = canvas.getContext('2d'); var image = new Image(); image.src = "/Content/ImageTestOne/logo-for-dissolve.png"; //682 x 111 pixel image image.onload = function () { context.drawImage(image, 0, 0); drawFrame(); }; function drawFrame() { window.requestAnimationFrame(drawFrame, canvas); imageData = context.getImageData(0, 0, canvas.width, canvas.height); //Do something

Get pixel color from resized canvas, on mouseover

為{幸葍}努か 提交于 2019-12-06 13:14:07
问题 I have checked this question which provides the perfect answer. But my problem is slightly different. I have a canvas of 300 x 300 and i am re-sizing the canvas using css to 200 x 60 . If i re-size the canvas using css i am not able to get the color value onmouseover . In the re-sized fiddle if you mouse over right below the red or blue rectangles you will notice it still says #FF0000 & #0000FF respectively while it should be #000000 . So how to make it work even with re-sized canvas? Fiddle:

getImageData in Firefox 3 causing NS_ERROR_DOM_SECURITY_ERR

删除回忆录丶 提交于 2019-12-06 11:17:43
I'm trying to develop an application that will use getImageData in javascript in Firefox 3, but I am getting a " NS_ERROR_DOM_SECURITY_ERR " on the getImageData call. The javascript and the image are both currently being served from by hard drive, which is apparently a security violation? When this is live they will both be served from the same domain, so it won't be a problem, but how can I develop in the meantime? You could try installing a local webserver such as Apache (on unix) or IIS (on Windows). That will ultimately give you the best local test bench for web-related stuff, because as

Getting the color value of a pixel on click of a mesh with three.js

人盡茶涼 提交于 2019-12-06 09:09:24
问题 I'm working with the last version of three.js and I got a scene with a 2D mesh, with gradient color. The color depends of a value assigned to each vertex. I would like to get the value of every point of my gradient by clicking on it with the mouse (by getting the color, and make some math for my value) I tried to use a system like this one, since it works here : http://jsbin.com/wepuca/2/edit?html,js,output var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d");

HTML5 Canvas drawing pixels with different color than the one provided

こ雲淡風輕ζ 提交于 2019-12-06 04:01:01
问题 After setting a certain colour as the fillStyle of the canvas and drawing a rectangle with fillRect , the colour of the rectangle sometimes differs a bit from the one provided (the getImageData returns different values - usually one of them is lower by 1). It seems to happen only when using rgba colours (and not with rgb ) but I actually do need to use the alpha channel. I've made a simple test suite on js fiddle for anyone who would like to look into this issue: http://jsfiddle.net/LaPdP/1/

Convert a byte array to image data without canvas

雨燕双飞 提交于 2019-12-05 06:07:07
Is it somehow possible to convert an byte array to image data without using canvas? I use currently something like this, however I think that can be done without canvas, or am I wrong? var canvas = document.getElementsByTagName("canvas")[0]; var ctx = canvas.getContext("2d"); var byteArray = [ 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, // red 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, // green 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255 // blue ]; var imageData = ctx.getImageData(0, 0, 10, 3); for(var i = 0; i < byteArray.length; i+=4){ imageData.data[i] = byteArray[i]; imageData

Javascript getImageData for canvas html5

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 00:27:47
问题 I've tearing my hair out! I got this working, thought 'i can afford not to save a version of this', then i .. broke the 'build'. The line myImageData = context.getImageData(0, 0, canvas.width, canvas.height); seems to breaking this, as an alert will work before, but not after it. The image itself is loading. Any and all suggestions welcomed ^_^ I'm at tether's end, and going to get RSI from kicking myself soon. var myImageData; var image_var = new Image(); image_var.onload = function () {

Get pixel color from resized canvas, on mouseover

不羁的心 提交于 2019-12-04 19:43:31
I have checked this question which provides the perfect answer. But my problem is slightly different. I have a canvas of 300 x 300 and i am re-sizing the canvas using css to 200 x 60 . If i re-size the canvas using css i am not able to get the color value onmouseover . In the re-sized fiddle if you mouse over right below the red or blue rectangles you will notice it still says #FF0000 & #0000FF respectively while it should be #000000 . So how to make it work even with re-sized canvas? Fiddle : Re-sized with css. Fiddle : Non re-sized. You need to apply a scale factor inside the mouse handler

Fast way to fill a canvas with an array of [rgba] colors

廉价感情. 提交于 2019-12-04 19:07:51
Providing you have an array of colors and you want to fill a canvas with its content, the fastest way I'm aware of is: var my_array = /* already have it */; var img_data = ctx.createImageData(canvas.width, canvas.height); for (var i=0; i<canvas.width*canvas.height; ++i) img_data[i] = my_array[i]; ctx.putImageData(img_data,0,0); This seems too slow as I'm copying the entire array twice! One to make the img_data and another to put it on the canvas. Isn't there a way to simply plug the original my_array into the element? You should directly make use of a typed array instead of a javascript array

HTML5 Canvas drawing pixels with different color than the one provided

半世苍凉 提交于 2019-12-04 07:10:52
After setting a certain colour as the fillStyle of the canvas and drawing a rectangle with fillRect , the colour of the rectangle sometimes differs a bit from the one provided (the getImageData returns different values - usually one of them is lower by 1). It seems to happen only when using rgba colours (and not with rgb ) but I actually do need to use the alpha channel. I've made a simple test suite on js fiddle for anyone who would like to look into this issue: http://jsfiddle.net/LaPdP/1/ Any ideas on why is this happening and if there is any way to fix that? If it at least happened always