FlashBuilder 4.5 :: 渲染文本,无需生命周期进行上采样
我需要找到一种方法,将渲染的客户端生成的文本从 72dpi(屏幕)“上采样”到 300dpi(打印)。这是一个真正的所见即所得应用程序,我们预计会有大量流量,因此需要客户端渲染。我们的应用程序有多种字体、字体大小、颜色、对齐方式,用户可以在文本区域中修改。问题是如何将72dpi转换为300dpi。我们已经完成了编辑器,我们只需要制作 300dpi 版本的文本区域。
我的想法
1) 获取文本区域并将高度、宽度和字体大小增加 300/72。 (如果字体大小需要整数,我可能需要增加字体,然后向下采样到高度/宽度)
2)在文本区域上使用 BitmapUtil.getSnapshot 来获取文本的渲染版本
问题
如何在内部渲染文本没有组件生命周期的文本区域?想象:
var textArea:TextArea = new TextArea();
textArea.text = "This is a test";
var bmd:BitmapData = textArea.render();
I need to find a way to "upsample" text from 72dpi (screen) to 300dpi (print) for rendered client generated text. This is a true WYSIWYG application and we're expecting a ton of traffic so client side rendering is a requirement. Our application has several fonts, font sizes, colors, alignments the user can modify in a textarea. The question is how to convert 72dpi to 300dpi. We have the editior complete, we just need to make 300dpi versions of the textarea.
MY IDEA
1) Get textarea and increase the height, width, and font size by 300/72. (if ints are needed on font size I may need to increase the font then down-sample to the height/width)
2) use BitmapUtil.getSnapshot on the textarea to get a rendered version of the text
THE QUESTION
How can I render text inside of a textarea without the component lifecycle? Imagine:
var textArea:TextArea = new TextArea();
textArea.text = "This is a test";
var bmd:BitmapData = textArea.render();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Flextras 所说,宽度/高度与 DPI 无关,除非您实际上将应用程序放大 4.16 倍。如果您的应用程序都具有基于矢量的图形,那么这应该不是问题。另外,在您尝试保存/打印位图之前,DPI 的概念在任何 Web 应用程序中都会丢失。
这绝对是可能的,但你必须自己想办法。
Like Flextras said, width/height has nothing to do with DPI, unless you actually zoom into the application by 4.16X. If your application all has vector based graphics, it shouldn't be a problem. Plus, the concept of DPI is lost in any web application until you're trying to save/print a bitmap.
It's definitely possible, but you'll have to figure it on your own.
从技术上讲,所有组件都位于内存中。我相信,您想要做的是渲染组件而不将其添加到容器中。
我们对 Flextras 组件上的水印正是这样做的。从概念上讲,我们创建了一个渲染实例的方法;像这样:
必须显式调用该方法。然后您可以使用“标准”过程将组件转换为位图。我认为我们使用标签;但同样的方法应该适用于任何给定的组件。
Technically, all components are in memory. What you want to do, I believe, is render a component without adding it to a container.
We do exactly this for the watermark on Flextras components. Conceptually we created a method to render the instance; like this:
The method must be explicitly called. Then you can use the 'standard' procedure for turning the component into a bitmap. I think we use a Label; but the same approach should work on any given component.
这是我用来解决创建 Spark TextArea 组件的文本和样式的可打印版本问题的最终方法。我最终将自定义组件 TextAreaRenderer(见下文)放置在 MXML 中并将可见性设置为 false。然后使用对此组件的引用来处理任何文本字段 (renderObject) 并获取 BitmapData 对象。
然后在文本区域更改后调用 TextAreaRenderer 以获得放大的位图。
感谢 www.Flextras.com 提供的建议与我一起解决了该问题。
Here is the final method I used to solve the problem of creating a printable version of the text and style of a Spark TextArea component. I ended up placing the custom component TextAreaRenderer (see below) in the MXML and setting the visibility to false. Then using the reference to this component to process any text field (renderObject) and get back a BitmapData object.
Then calling the TextAreaRenderer after the text area is changed to get a scaled up bitmap.
Thanks to the advice from www.Flextras.com for working through the issue with me.