apache-flex - ( Flex ) 如何在没有滚动条的情况下获取整个组件的图像快照?

标签 apache-flex image printing components capture

我可以拍摄组件的快照。但问题是带有滚动条的组件有点大。保存的图像有滚动条(只有可见区域被保存)。我需要的是我希望将整个组件保存为图像。

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

但在我的情况下,我希望使用 ImageSnapShot(而不是通过 FlexPrintJob)保存它。

感谢提前,
斯里斯

最佳答案

我以为我知道该怎么做,但似乎有很多尴尬的问题。我让它工作了,但它并不好。 :-( 也许你可以改进它。

这是示例应用程序的代码。下面是 MyCanvas 类的代码。当您单击按钮时,应绘制 Canvas 容器的图像,但没有滚动条。

    <?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>

MyCanvas 类:
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();
        }
    }
}

关于apache-flex - ( Flex ) 如何在没有滚动条的情况下获取整个组件的图像快照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2446269/

相关文章:

apache-flex - Flex 中的同步对话框?

apache-flex - 如何在 Flex 3 中在运行时确定函数的参数计数?

apache-flex - 如何在 Flex 中以编程方式拖放 Sprite?

image - 无效的 JPEG 格式 : missing SOI marker

PHP/GD - 查找图像资源类型

delphi - 如何打印大于一页的图像

android - FLEX - ZXing - Android、移动 - 条码读取器

c# - 我想从 mysql 数据库检索图像,但出现错误 "system parameter is not valid at system drawing image fromstream... "

python - 如何获取 future 导入的 print() 函数的 Python 2.6 文档?

apache-flex - 柔性打印 - 可以做到吗?