0

我有一个 5000 x 5000 像素的图像。它会定期放大和缩小,以使图像的不同部分适合窗口。

我正在制作一个功能,专注于图像上的不同位置(如地图),然后放大到我指定的特定比例。

我将我的观点传递给这个函数(例如 new Point(2000,2500))但是这总是会中断,因为它与图像无关。

如何在任何给定时间以图像的给定比例使点相对于图像?

附加信息:我在这里使用指南http://www.adobe.com/devnet/flex/samples/fig_panzoom.html进行平移和缩放功能。

解决了:

我的一个陷阱是我使用了可能的 bitmapScaleFactor > 1,这会弄乱缩放比例。这是适合我使用的最后一个功能。

protected function testFocus(p:Point):void
        {
            var content:ContentRectangle = boardViewer._contentRectangle;
            var panToPoint:PanToPointCommand = new PanToPointCommand(boardViewer, content);
            var scale:Number = boardViewer.bitmapScaleFactor;

            var location = new Point((p.x*scale)+content.x, (p.y*scale)+content.y);             
            var center = new Point(boardViewer.width/2, boardViewer.height/2);

            //Move the point to the center
            panToPoint.fromPoint = location;
            panToPoint.toPoint = center;
            panToPoint.execute();
        }
4

2 回答 2

1

I've not tested this but how about using the scale factor that is being applied to the image to alter the point coordinates.

e.g.

var scaler:Number = 0.5;

image.scaleX = image.scaleY = scaler;

new Point(2000*scaler,2500*scaler);
于 2012-06-02T17:45:49.497 回答
0

你在找DisplayObject.mouseX/mouseY吗?然而,这些没有考虑任何轮换。

要考虑轮换,您可以执行以下操作(未经测试的代码):

var mat:Matrix = image.transform.concatenatedMatrix;
mat.invert();

// now use mat to transform point from 'stage space' to 'image space'
var pImage:Point = mat.transform(new Point(stage.mouseX, stage.mouseY));
于 2012-06-02T20:05:58.573 回答