不幸的是,过滤器在GPU模式下不起作用(投影,发光).我正在寻找机会在这种模式下使用这些效果来发短信.我会欢迎任何建议. 正如Astraport所提到的,每次使用bitmapData.draw()更新文本时,您都需
如果使用textField.getBounds来确定所需位图数据的大小,则生成的边界矩形将不包括由于过滤器而产生的额外大小(例如,DropShadowFilter根据“距离”将某些像素突出显示文本框的一侧和’模糊’).要确保在绘制位图时包含过滤器,还需要使用bitmapData.generateFilterRect()来获取正确的rect大小.
代码段(未经测试,但总体思路):
// 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;