0

スプライトに合わせて画像のサイズを変更することになっている ActionScript コードのこのスニペットがあります:

package 
{
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.events.Event;

    public class Main extends Sprite 
    {
        [Embed(source = 'img.png')]
        private var TheImage:Class;

        public static const  TheImageWidth:Number = 1300;
        public static const TheImageHeight:Number = 1300;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point

            var image:Bitmap = new TheImage();

            addChild(image);

            image.scaleX = width / TheImageWidth;
            image.scaleY = height / TheImageHeight;
        }

    }

}

なぜ機能しないのですか?画像の寸法が正しくありません。

4

2 に答える 2

0

私はイメージのためにこのようなことをしなければなりませんでした。ArcGIS for Flex 2.5 を使用して MapImage と MapImageLayer を使用すると問題が発生しました。3.5 で修正されたようですが、とにかく画像をスプライトに入れて、スプライトの幅に基づいて画像をペイントする必要がありました。画像をスプライトの寸法にスケーリングする場合は、Matrix API を使用し、scale メソッドを使用する必要があります。これに渡される値は、スプライトの幅を画像の幅で割ったものである必要があります。これは、画像がスプライトよりも大きいと仮定した場合です。高さも同じようにします。これが、タスクを達成するために使用したコードです。

                const point:MapPoint = geometry as MapPoint;

                sprite.x = toScreenX(map, point.x);
                sprite.y = toScreenY(map, point.y);

                // grab left x point for upper left then for lower right
                // actua
                var bottomLeftX:Number = toScreenX(map, geomertyWrapper.extent.xmin);
                var topRightX:Number = toScreenX(map, geomertyWrapper.extent.xmax);

                var bottomLeftY:Number = toScreenY(map, geomertyWrapper.extent.ymin);
                var topRightY:Number = toScreenY(map, geomertyWrapper.extent.ymax);

                iconWidth = Math.abs(topRightX - bottomLeftX);
                iconHeight = Math.abs(topRightY - bottomLeftY);

                sprite.width = iconWidth;
                sprite.height = iconHeight;

                var scaleX:Number = iconWidth/bitmapData.width;
                var scaleY:Number = iconHeight/bitmapData.height;

                m_matrix.a = 1.0;
                m_matrix.d = 1.0;
                m_matrix.scale(scaleX, scaleY);
                m_matrix.tx = -iconWidth / 2;
                m_matrix.ty = -iconHeight / 2;

                //Values needed for drawing AlertNotificationInstance

                sprite.graphics.beginBitmapFill(m_bitmapData, m_matrix, false, false);
                sprite.graphics.drawRect(m_matrix.tx, m_matrix.ty, 
                    iconWidth, 
                    iconHeight);
                sprite.graphics.endFill(); 

お役に立てれば。

于 2013-11-06T19:31:27.723 に答える
0

試す

image.image.content.width = TheImageWidth;
image.image.content.height = TheImageHeight;
于 2010-04-13T13:40:20.697 に答える