Move pivot point without moving position rect in a script (C#)

How would I go about moving the pivot of the rectTrans of a UI Image? I can do this in the editor no problem. Grab the blue circle that represents the pivot point, drag it about and only the pivot point changes position.
If I try and do the same using a script by:

myImage.rectTransform.pivot = newPosition;

This changes not only the pivot point where I want it, but also moves the entire rect in the opposite direction on screen. The editor apparently automatically compensates to keep the rect position fixed on screen. Can anyone tell me how it compensates?

The ultimate goal is to be able to scale the image around the pivot point and the image remaining stationary in relation to the pivot point. It is of course going to expand away from the pivot point.

substract the old pivot position from the new pivot position and multiply this by the object size and scale: this is the distance you want to move so the object will remain in place. Add it to the current object’s position.
If there’s rotation, it gets a bit more complicated. RectTransform do not do transformations for you as regular Transforms do (I hope they’ll add that soon).

Thank you. It looks so obvious in retrospect. I will try as soon as I have time again. More pressing needs now :).

turns out RectTransform does transformations from-to world! I was using it wrong.
This doesn’t affect you much though, since you’re only changing the pivot.