$ 0 0 Why do you need to resize and resample the image? This is probably what is messing up your image. Just setting the density should be enough.