数学将图像置于屏幕中心?

alp*_*der 0 math image

给定尺寸(w,h)和尺寸照片(ww,hh)的屏幕,如何计算屏幕上的x,y点以放置图像的左上角,使图像居中?

谢谢!

Kar*_*lis 7

x = (w - ww) / 2;
y = (h - hh) / 2;
Run Code Online (Sandbox Code Playgroud)


red*_*bmk 5

x = (w/2) - (ww/2)
y = (h/2) - (hh/2)
Run Code Online (Sandbox Code Playgroud)