I have a series of functions that builds a rgba sequence array, and I'm planning to apply this data to a canvas object. I'm not sure how to convert the rgba (already in 0-255 values) into a proper imageData object that I can use .putImageData with.
var new_canvas = document.createElement('canvas');
var mc_ctx = new_canvas.getContext('2d');
new_canvas.width = 50;
new_canvas.height = 50;
var mc_imageData = mc_ctx.getImageData(0,0, 50, 50);
var mc_px_data = mc_imageData.data;
for ( var i = 0; i <= rgba_array.length; i++ ) {
mc_px_data[i] = rgba_array[i];
}
mc_ctx.putImageData(mc_imageData, 0, 0);
All i get is white, even though an output of the rgba_array values shows the proper stream of values.
rgba_arrayget defined? are you SURE it contains anImageDataobject? what doesconsole.log(rgba_array)show?dataproperty with you array's values, but you need the ImageData object.context.createImageData(width, height)method, it's way less heavier than thegetImageData()one. Second, in order to be able t elp you, we'll need some info about thisrgba_array. Are you sure it does only contain the 50*50 px rgba values (if sorgba_array.lengthshould be10000). Then, are you sure all its 10000 firsts values are not set to255? If you still don't find your problem, then check that you actually append your canvas and that it should be visible in your doc.