什么是渲染以最优的方式 UIComponent
还没有被添加到舞台上? (我用的UIComponents作为渲染的对象,并想呈现的图像输出,滤波等新副本。)
What is the best way to render to a UIComponent
which hasn't been added to the stage? (I'm using UIComponents as renderers for objects, and want to render new copies for image export, filtering, etc.)
两种策略我见过/使用到目前为止,包括实现组件,以确保它要求所有的生命周期方法:
Two strategies I've seen/used so far include realizing the component to ensure it calls all the lifecycle methods:
组件添加到 Application.application
,渲染的BitmapData.draw(),删除组件。这与我所看到的打印未实现的组件做得很好。
Add the component to Application.application
, render with BitmapData.draw(), remove component. This is similar to what I've seen done for printing unrealized components as well.
组件添加到一个弹出窗口,渲染的BitmapData.draw(),渲染完成后解散弹出。
Add the component to a pop up window, render with BitmapData.draw(), dismiss popup after rendering complete.
我相信这两个仅仅依靠用户界面不清爽,而当前线程/事件被执行,但(1)还可以依靠在组件上正在实现拿出来看。
I believe both of these just rely on the UI not refreshing while the current thread/event is executing, though (1) could also rely on the component being realized out of view.
有没有更好的办法?
我已经在过去有很多成功使用了哪些如下:
What I've used in the past with much success is the following:
创建组件的新实例 添加事件侦听器FlexEvent.CREATION_COMPLETE 设置可见=假在组件上 添加组件为主要应用的子 当创建的组件,事件侦听器函数将被调用。该逻辑的其余部分应该放在/从你的事件侦听器函数调用 删除您在步骤2中添加的事件侦听器。 使用ImageSnapshot.captureImage()或captureBitmapData()来捕获组件的视觉重新presentation。 从主应用程序中删除的组件 在处理图像数据,因为你需要。我用这个来快照在服务器端生成的PDF的各种Flex图表组件的使用。得到的BitmapData后,我为Base64使用PNGEn codeR或JPEGEn codeR类COM preSS数据,然后连接$ C C $它上传到服务器。
I've used this to snapshot various Flex charting components for use in PDF's generated on the server side. After getting the BitmapData I use the PNGEncoder or JPEGEncoder classes to compress the data, then encode it in Base64 before uploading to the server.