在 GPU 模式下对文本使用过滤器 AIR mobile [英] Use filters for Text in GPU mode AIR mobile

查看:23
本文介绍了在 GPU 模式下对文本使用过滤器 AIR mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,滤镜在 GPU 模式下不起作用(投影、发光).我正在寻找机会在这种模式下将这些效果用于文本.我欢迎任何建议.

Unfortunately the filters do not work (drop shadow, glow) in GPU mode. I'm looking for an opportunity to use these effects to text in this mode. I will welcome any advice.

推荐答案

Astraport 提到,每次使用 bitmapData.draw()bitmapData.draw() 更新文本时,您都需要将文本字段绘制为 bitmapData代码>.

As Astraport mentions, you'll need to draw the textfield out to a bitmapData every time you update the text using bitmapData.draw().

如果您使用 textField.getBounds 来确定您需要的 bitmapData 的大小,则生成的边界矩形将不包括由于过滤器而产生的额外大小(例如 DropShadowFilter 伸出文本框由某些像素取决于距离"和模糊").为了确保在绘制位图时包含过滤器,您还需要使用 bitmapData.generateFilterRect() 来获得正确大小的矩形.

If you use textField.getBounds to determine the size of the bitmapData you need, the resulting bounds rectangle will not include the extra size due to the filter (e.g. a DropShadowFilter sticks out the side of the textbox by certain pixels depending on the 'distance' and 'blur'). To ensure that you include the filters when you draw the bitmap, you'll also need to use bitmapData.generateFilterRect() to get the correct size rect.

代码片段(未经测试,但总体思路):

Code snippet (untested, but general idea):

// Remember the transform matrix of the text field
var offset : Matrix = myTextField.transform.matrix.clone();
// Get the bounds of just the textfield (does not include filters)
var tfBounds : Rectangle = myTextField.getBounds( myTextField.parent );     
// Create a bitmapData that is used just to calculate the size of the filters
var tempBD : BitmpaData = new BitmapData( Math.ceil(tfBounds.width), Math.ceil(tfBounds.height) );
// Make a copy of the textField bounds. We'll adjust this with the filters
var finalBounds : rectangle = tfBounds.clone();
// Step through each filter in the textField and adjust our bounds to include them all
var filterBounds : rectangle;
for each (var filter : BitmapFilter in myTextField.filters) {
    filterBounds = tempBD.generateFilterRect( tfBounds, filter );
    finalBounds.left = Math.min( finalBounds.left, filterBounds.left );
    finalBounds.right = Math.max( finalBounds.right, filterBounds.right );
    finalBounds.top = Math.min( finalBounds.top, filterBounds.top );
    finalBounds.bottom = Math.max( finalBounds.bottom, filterBounds.bottom );
}

// Now draw the textfield to a new bitmpaData
var textFieldBD : BitmpaData = new BitmapData( Math.ceil(finalBounds.width), math.ceil(finalBounds.height) );
offset.tx = -finalBounds.x;
offset.ty = -finalBounds.y;
textFieldBD.draw( myTextField.parent, offset, myTextField.transform.colorTransform );

// Create a bitmap and add the bitmap data. Note: normally you would create a
// bitmap once and just update the bitmpaData
var bitmap : Bitmap = new Bitmap();
myTextField.parent.addChild( bitmap );

// Position the bitmap in same place as textField
bitmap.bitmapData = textFieldBD;
bitmap.x = myTextField.x - finalBounds.x;
bitmap.y = myTextField.y - finalBounds.y;
myTextField.visible = false;

这篇关于在 GPU 模式下对文本使用过滤器 AIR mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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