@DaWei, your intended result almost looks like it could be shifted and overlayed 1 or 2 pixel(s) to the right, and end up looking like what your application outputs.
Perhaps you missed something simple and are using your indexes incorrectly. I think some libraries also consider the first pixel the zero'eth, and some the first.
Things to consider.
