Modified resizeCanvas() to reduce flashing