在C#中计算新的位置值

时间:2012-09-20 19:56:41

标签: c# asp.net geometry calculus

我有一个包含一些元素的文档。该文件是INDD文件。我试图在webview中显示它,但尺寸小于原始大小。 我正在使用ImageMapper(ASP.NET)来标记webview中的不同元素。 问题是我没有在webview中的不同位置找到正确的位置。 我得到了新位置的正确大小,但没有位置。 我按以下方式进行了计算:

Original size (INDD document)
DocumentWidth = 768
DocumentHeight = 1024
New Size (Size of the webview)
Width = 522
Height = 696

percentW = newWidth(Webview)/DocumentWidth
percentH = newHeight(Webview)/DocumentHeight;

根据这些百分比值,我计算了ImageMapper中需要的所有新值(上,左,下,右)。

该公式

myPrecent = (percentW/percentH) * 100;
        result =  myPrecent * ((top,left,right,bottom) / 100);

结果变量应表示将在ImagMapper中的斑点中使用的新值。

我认为我的计算错误,但我无法弄清楚我做错了什么。如果有人知道我做错了什么,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

不要将它们视为百分比,而应将它们视为缩放因子。

verticalScaling = Height/DocumentHeight
horizontalScaling = Width/DocumentWidth

newTop = Top * verticalScaling
newLeft = Left * horizontalScaling
newBottom = Bottom * verticalScaling
newRight = Right * horizontalScaling