如何将 BitmapFilter 渲染到 BMD?

发布于 2025-01-01 08:41:39 字数 350 浏览 1 评论 0原文

如何将应用于精灵的 BitmapFilter(例如 DropShadowFilter)渲染到单独的 BitmapData 层?然后将其放置在所有物体下方。

例如,如果您有两个彼此重叠的矩形精灵,并且对每个精灵应用了 DropShadowFilter,则结果将是滤镜覆盖并遮挡另一个矩形精灵 - 如下所示。

注意:每个过滤器可能有不同的设置,因此我不能只将统一的过滤器应用于包含的精灵。 另外:理想情况下,该解决方案可以扩展以同时处理许多动画精灵。

在此处输入图像描述

How would you render a BitmapFilter (such as DropShadowFilter) applied to a sprite, to a seperate BitmapData Layer? which would then be placed beneath all objects.

For instance if you have two rectangular sprites overlapping each other, with a DropShadowFilter applied to each, the result would be the filter overlaying and obscuring the other rectangular sprite - as shown below.

note: each filter may have different settings and so I cant just apply a uniform filter to a containing sprite. also: ideally this solution will be scalable to handle many animated sprites at the same time.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看轻我的陪伴 2025-01-08 08:41:39

我想说最简单的方法是保留每个 Sprite 的轮廓副本,并对其应用 DropShadowFilter。在滤镜上,设置 dropShadowFilter.hideObject = true; - 这将仅渲染阴影。然后将所有轮廓阴影添加到单个容器 Sprite 中并使用 addChildAt(container,0) ,因此它将渲染在其他所有内容的下方。

I'd say the easiest way to do this is to keep an outline copy of each of your Sprites, to which you apply the DropShadowFilter. On the filter, set dropShadowFilter.hideObject = true; - this will render only the shadow. Then add all the outline shadows to a single container Sprite and use addChildAt(container,0), so it will be rendered below everything else.

中性美 2025-01-08 08:41:39

我的方法是将每个 DisplayObject 的过滤器属性 knockout 设置为 true 绘制到 BitmapData 对象,然后重置每个过滤器的knockout 恢复到原始状态。一个简单的例子来证明这一点:

var s:Sprite = new Sprite();
s.graphics.beginFill(0xFF0000);
s.graphics.drawRect(0,0,40,40);
s.graphics.endFill();
var shadow:DropShadowFilter = new DropShadowFilter();
s.filters = [shadow];


function renderFilter(sprite:Sprite):Bitmap
{
   var bd:BitmapData = new BitmapData(sprite.width * 1.2, sprite.height * 1.2, true); //extra 20% for the filter data, you might have to adjust this value depending on your filter's size
  var filter:DropShadowFilter = sprite.filters[0];
  var originalKnockout:Boolean = filter.knockout;
  filter.knockout = true;
  bd.draw(sprite);
  filter.knockout = originalKnockout;
  sprite.filters[0] = filter;
  var bitmap:Bitmap = new Bitmap(bd);
  return bitmap;
}
renderFilter(s); // here you have filter's rendering;

My approach would be drawing each DisplayObject with it's filter's property knockout set to true to a BitmapData object, then reseting each filter's knockout to original state. A quick example to demonstrate this:

var s:Sprite = new Sprite();
s.graphics.beginFill(0xFF0000);
s.graphics.drawRect(0,0,40,40);
s.graphics.endFill();
var shadow:DropShadowFilter = new DropShadowFilter();
s.filters = [shadow];


function renderFilter(sprite:Sprite):Bitmap
{
   var bd:BitmapData = new BitmapData(sprite.width * 1.2, sprite.height * 1.2, true); //extra 20% for the filter data, you might have to adjust this value depending on your filter's size
  var filter:DropShadowFilter = sprite.filters[0];
  var originalKnockout:Boolean = filter.knockout;
  filter.knockout = true;
  bd.draw(sprite);
  filter.knockout = originalKnockout;
  sprite.filters[0] = filter;
  var bitmap:Bitmap = new Bitmap(bd);
  return bitmap;
}
renderFilter(s); // here you have filter's rendering;
恍梦境° 2025-01-08 08:41:39

我认为您正在寻找 BitmapData.applyFilter()。它将任何 BitmapFilter 类型应用于 BitmapData 对象。位图滤镜是一系列滤镜类型的父类,包括模糊、发光和着色器滤镜。

http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#applyFilter()

http://help.adobe.com/en_US/FlashPlatform /reference/actionscript/3/flash/filters/BitmapFilter.html

I think you are looking for BitmapData.applyFilter(). It applies any BitmapFilter type to your BitmapData object. Bitmap filter is the parent class for a bunch of Filter types, including Blur, Glow, and Shader filters.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#applyFilter()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filters/BitmapFilter.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文