使用过滤器的文本在GPU模式AIR移动(Use filters for Text in GPU mo

2019-06-28 07:46发布

不幸的是,过滤器不工作在GPU模式(阴影,光晕)。 我正在寻找在此模式下使用这些效果文本的机会。 我会欢迎任何意见。

Answer 1:

作为Astraport提到,你需要每次绘制文本字段出一个位图数据更新使用文本bitmapData.draw()

如果您使用textField.getBounds确定的位图数据的你需要的大小,所产生的边界矩形将不包括因过滤多余的大小(例如一个的DropShadowFilter伸出通过取决于“距离”某些像素的文本框的侧面和“模糊”)。 为确保您有过滤器,当你绘制位图,你还需要使用bitmapData.generateFilterRect()以获得正确的尺寸矩形。

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

// 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;


Answer 2:

下面是如何将任何转换DisplayObjectBitmap -在AIR GPU移动“恢复”过滤器效果有用rendermode 。 这是Pixelthis的溶液,固定,优化和测试:

    // => 'bitmap' must belong to the same parent as 'obj'. 'obj' should be invisible.
    static public function Update(obj:DisplayObject, bitmap:Bitmap):void {
        //trace("CacheToBmp",obj.name);

        // Remember the transform matrix of the text field
        var offset:Matrix = obj.transform.matrix.clone();
        // Get the bounds of just the textfield (does not include filters)
        var bounds:Rectangle = obj.getBounds(obj);
        // Create a bitmapData that is used just to calculate the size of the filters
        var tempBD:BitmapData = new BitmapData( Math.ceil(bounds.width), Math.ceil(bounds.height), false );
        bounds.width = obj.width;
        bounds.height = obj.height;
        // Make a copy of the textField bounds. We'll adjust this with the filters
        var finalBounds:Rectangle = new Rectangle(0,0,bounds.width,bounds.height);

        // Step through each filter in the textField and adjust our bounds to include them all
        var filterBounds:Rectangle;
        for each (var filter:BitmapFilter in obj.filters) {
            filterBounds = tempBD.generateFilterRect( tempBD.rect, filter );
            finalBounds = finalBounds.union(filterBounds);
        }
        finalBounds.offset(bounds.x,bounds.y);
        finalBounds.x = Math.floor(finalBounds.x);
        finalBounds.y = Math.floor(finalBounds.y);
        finalBounds.width = Math.ceil(finalBounds.width);
        finalBounds.height = Math.ceil(finalBounds.height);

        // Now draw the textfield to a new bitmpaData
        var data:BitmapData = new BitmapData( finalBounds.width, finalBounds.height, false, 0 );
        offset.tx = -finalBounds.x;
        offset.ty = -finalBounds.y;
        data.drawWithQuality( obj, offset, obj.transform.colorTransform, obj.blendMode, null, true, StageQuality.HIGH );
        bitmap.bitmapData = data;

        // Position the bitmap in same place as 'obj'
        bitmap.x = obj.transform.matrix.tx + finalBounds.x;
        bitmap.y = obj.transform.matrix.ty + finalBounds.y;
    }


Answer 3:

基本的想法是应用过滤器正常然后绘制显示对象为BitmapData和位图添加到阶段。 见http://forums.adobe.com/message/3934192的一个例子。

如果您将其应用到文本是静态的,应该是很容易的事,但如果你想申请这个动态文本(例如,这是一个得分计数器,它会经常发生变化,或文本用户可编辑)我想象它可能会开始招人烦,但我不知道任何其他解决方案。



文章来源: Use filters for Text in GPU mode AIR mobile