我误解了的Bitmap:原来Bitmap有两种方式来绘制BitmapData的(转)
别以为,你用了Bitmap而不是矢量,渲染性能就是最快的。万万没想到,原来Bitmap绘制BitmapData有两种方式:使用矢量渲染器作为填充位图形状,或使用更快的像素复制例程(using the vector renderer as a fill-bitmap shape, or using a faster pixel-copying routine)。这是关于Bitmap的API文档里说的(http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/display/Bitmap.html)只有使用了第二种绘制方式,渲染Bitmap才是最快的。在以下条件,Flash Player才会使用第二种方式:
- 不能将拉伸、旋转或倾斜效果应用于 Bitmap 对象。
- 不能将颜色转换应用于 Bitmap 对象。
- 不能将混合模式应用于 Bitmap 对象。
- 不能通过蒙版或
setMask()方法进行剪裁。 - 图像本身不能是遮罩。
- 目标坐标必须位于一个整像素边界上。
这是原汁原味的英文版说明:
- No stretching, rotation, or skewing can be applied to the Bitmap object.
- No color transform can be applied to the Bitmap object.
- No blend mode can be applied to the Bitmap object.
- No clipping can be done through mask layers or
setMask()methods. - The image itself cannot be a mask.
- The destination coordinates must be on a whole pixel boundary.
个人猜想,“使用矢量渲染器作为填充位图形状”这种绘制方式就像在内部创建了shape对象,然后进行位图填充,那么,肯定比“像素复制例程”方式使用了更多的内存。于是,我创建了10000个只有一像素的位图,分别尝试了使用blendMode和没有使用blendMode的情况,观察了内存(flash.system.System.totalMemory),证明了这一点。
最近发生在我身边的一连串事件(设置了scrollRect属性或大量位图叠加时出现透明像素不透明的情况),肯定与Bitmap这个特性有关系。我千方百计想证明这一点,但由于Flash Player就像一个黑盒,你不可能看到源码,所以Adobe文档上说的,大家相信就是了。

浙公网安备 33010602011771号