Make sure you also copy the alpha channel as each pixels consist of four channels (RGBA):
layerDataCopy.data[pp] = layerDataOri.data[pp];
layerDataCopy.data[pp + 1] = layerDataOri.data[pp + 1];
layerDataCopy.data[pp + 2] = layerDataOri.data[pp + 2];
layerDataCopy.data[pp + 3] = layerDataOri.data[pp + 3]; // alpha
Note that pp must also be quantized by 4 to point to a valid pixel (you're now showing how you generate the positions in the question, so just in case).
If the canvas you're getting the copy buffer from is blank (nothing drawn into it) all pixels will be transparent by default. So when, during the copy, the alpha channel isn't copied over the pixel will remain transparent.
You could also use createImageData
instead of getImageData
for the copy buffer if it isn't containing any data in advance (it's faster).