Move the loop that sets the pixels in DirectUtils::createImage from Java to a JS native

Fixes #315.