Apache flex (Flex)如何在没有滚动条的情况下获得整个组件的imagesnapshot?

Apache flex (Flex)如何在没有滚动条的情况下获得整个组件的imagesnapshot?,apache-flex,image,printing,components,capture,Apache Flex,Image,Printing,Components,Capture,我可以拍摄组件的快照。但问题是,滚动条的组件太小了。保存的图像具有滚动条(仅保存可见区域)。我需要的是我希望整个组件被保存为一个图像 当我们使用FlexPrintJob打印组件时,可以使用这个确切的功能,其中通过设置FlexPrintJobScaleType.NONE 但在我的例子中,我希望使用ImageSnapShot保存它(而不是通过FlexPrintJob) 提前谢谢, Sriss我以为我知道怎么做,但似乎有很多棘手的问题。我让它工作了,但不太好-(也许你可以改进一下 下面是一个示例应用程

我可以拍摄组件的快照。但问题是,滚动条的组件太小了。保存的图像具有滚动条(仅保存可见区域)。我需要的是我希望整个组件被保存为一个图像

当我们使用FlexPrintJob打印组件时,可以使用这个确切的功能,其中通过设置FlexPrintJobScaleType.NONE

但在我的例子中,我希望使用ImageSnapShot保存它(而不是通过FlexPrintJob)

提前谢谢,
Sriss

我以为我知道怎么做,但似乎有很多棘手的问题。我让它工作了,但不太好-(也许你可以改进一下

下面是一个示例应用程序的代码。下面是MyCanvas类的代码。单击按钮时,应绘制画布容器的图像,但不带滚动条

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:my="*">
        <mx:Script><![CDATA[
            import flash.display.BitmapData;
            import flash.events.Event;
            import mx.containers.Canvas;
            import mx.graphics.ImageSnapshot;
            import flash.geom.Matrix;
            import mx.core.ScrollPolicy;

            public function onclick():void
            {
                var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(canvas);
                canvas.addEventListener("BitMapReady", onBitMapReady);
                canvas.horizontalScrollPolicy = ScrollPolicy.OFF;
                canvas.CreateBitMapData();
            }
            private function onBitMapReady(e:Event):void
            {
                DrawBitmapDataAt(canvas.bitMapData, 100, 100);
                canvas.removeEventListener("BitMapReady", onBitMapReady);
                canvas.horizontalScrollPolicy = ScrollPolicy.AUTO;
            }
            private function DrawBitmapDataAt(bitmapData:BitmapData,x:int,y:int):void
            {
                var matrix:Matrix = new Matrix();
                matrix.tx = x;
                matrix.ty = y;
                box.graphics.lineStyle(0,0,0);
                box.graphics.beginBitmapFill(bitmapData, matrix, false);
                box.graphics.drawRect(x,y,bitmapData.width,bitmapData.height);
            }
        ]]></mx:Script>
        <mx:Box id="box">
            <my:MyCanvas width="50" height="50" backgroundColor="white" id="canvas">
                <mx:Button label="Hello" click="onclick()" />
            </my:MyCanvas>
        </mx:Box>
    </mx:Application>
package  
{
    import flash.events.Event;
    import flash.events.TimerEvent;
    import mx.containers.Canvas;
    import flash.display.BitmapData;
    import mx.core.ScrollPolicy;
    import mx.graphics.ImageSnapshot;
    import flash.utils.Timer;

    public class MyCanvas extends Canvas
    {
        public var bitMapData:BitmapData;
        private var creatingBitMap:Boolean = false;
        private var timer:Timer;

        public function CreateBitMapData():void
        {
            this.horizontalScrollPolicy = ScrollPolicy.OFF;
            creatingBitMap = true;
        }
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if (creatingBitMap == true && this.horizontalScrollBar == null)
            {
                bitMapData = ImageSnapshot.captureBitmapData(this);
                this.dispatchEvent(new Event("BitMapReady"));
                creatingBitMap = false;
                timer = new Timer(10);
                timer.addEventListener(TimerEvent.TIMER, onTimer);
                this.width += 1;
                timer.start();
            }
        }
        private function onTimer(e:TimerEvent):void
        {
            this.width -= 1;
            trace("timer");
            timer.removeEventListener(TimerEvent.TIMER, onTimer);
            timer.stop();
        }
    }
}