Flex:将未实现的 UIComponent 渲染到 BitmapData? [英] Flex: Render an unrealized UIComponent to BitmapData?

查看:27
本文介绍了Flex:将未实现的 UIComponent 渲染到 BitmapData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

渲染到尚未添加到舞台的 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:

  1. 将组件添加到 Application.application,使用 BitmapData.draw() 渲染,移除组件.这与我所看到的打印未实现组件的做法类似.

  1. 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.

我相信这两者都只是依赖于在当前线程/事件执行时 UI 不刷新,尽管 (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:

  1. 创建组件的新实例
  2. 为 FlexEvent.CREATION_COMPLETE 添加事件侦听器
  3. 在组件上设置visible=false
  4. 将组件添加为主应用程序的子项
  5. 创建组件时,将调用事件侦听器函数.其余的逻辑应该放在/从您的事件侦听器函数中调用
  6. 删除您在第 2 步中添加的事件侦听器.
  7. 使用 ImageSnapshot.captureImage() 或 captureBitmapData() 来捕捉组件的视觉表现.
  8. 从主应用程序中删除组件
  9. 根据需要处理图像数据.

我已经用它来对各种 Flex 图表组件进行快照,以便在服务器端生成的 PDF 中使用.获取 BitmapData 后,我使用 PNGEncoder 或 JPEGEncoder 类来压缩数据,然后在上传到服务器之前以 Base64 对其进行编码.

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.

这篇关于Flex:将未实现的 UIComponent 渲染到 BitmapData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆