不幸的是,在GPU模式下,濾鏡不起作用(投影,發光)。我正在尋找一個機會在這種模式下使用這些效果文本。我會歡迎任何建議。在GPU模式下對文本使用濾鏡AIR mobile
4
A
回答
6
正如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;
0
其基本思想是按照正常方式應用濾鏡,然後將顯示對象繪製爲位圖數據並將位圖添加到舞臺上。一個例子見http://forums.adobe.com/message/3934192。
如果要應用此文本是靜態的,應該很容易做到,但是如果您想要應用此動態文本(例如,頻繁更改的分數計數器或用戶定義的文本)可編輯)我想可能會開始討厭,但我不知道任何其他解決方案。
+0
我看到了這個建議,但它不適合我。我正在使用動態文本。 – Astraport
2
這裏是如何轉換成任何DisplayObject
爲Bitmap
- 有用的 「恢復」,在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;
}
相關問題
- 1. GPU圖像濾鏡
- 2. GPU VS CPU渲染模式的Adobe AIR
- 3. AIR Stage3D-將GPU濾鏡效果限制到舞臺的一部分
- 4. 使用濾鏡
- 5. 使用模糊濾鏡的OpenCV邊框模式問題
- 6. AIR Mobile嵌入式字體
- 7. 如何在文本模式下使用orgstruct模式?
- 8. 如何使用意圖過濾器來過濾文本模式
- 9. 在GPU上運行tensorflow文本模型
- 10. 適用於Android的遠程下載文件(Air mobile)
- 11. 使用AIR和Actionscript 3.0在Android Mobile中加載文件
- 12. 緩解模糊濾鏡
- 13. 的Adobe AIR的cacheAsBitmap和GPU渲染
- 14. AIR renderMode GPU vs renderMode direct
- 15. CSS對比度濾鏡
- 16. Air Mobile應用程序-debug
- 17. C#,XNA,如何在2D模式下選擇圖像最小化濾鏡?
- 18. Adobe Air Mobile:如何在啓動屏幕上放置文本
- 19. 以編程方式在Windows Mobile 6.5中更改文本模式
- 20. 將模糊濾鏡應用於BitmapData
- 21. 在GPU中分配內存,flash/air
- 22. iPad上的性能突然下降使用renderMode = GPU的AIR應用程序
- 23. 使用Adobe AIR下載文件
- 24. AIR從下載的模式文件創建本地SQLite數據庫
- 25. 在文本中查找以下模式
- 26. 使用Adobe AIR下載文件的最佳方式
- 27. 下載保存在目錄下自動文件中使用AIR
- 28. PdfPHeaderCell在文本模式下對齊內容
- 29. 使用scipy應用Sobel濾鏡
- 30. 哪種模式下使用對位圖
GPU呈現模式限制: 不支持篩選。 – Astraport