【问题标题】:operations with BitmapData使用 BitmapData 进行操作
【发布时间】:2011-04-20 11:39:21
【问题描述】:

我们有一个方形影片剪辑,上面有一些 clild 影片剪辑。考虑一个正方形的对角线。我想用影片剪辑的 bimap 数据进行以下转换:位于对角线上方的三角形应保持不变,下三角形应替换为上三角形的对称反射。

有没有一种简单的方法来做到这一点?

【问题讨论】:

  • 这听起来有点像教科书。

标签: actionscript-3 bitmap


【解决方案1】:

确切地说,方法是对电影进行快照,然后对其进行镜像,再进行快照并将这两个快照合并。 请注意,您将获得的内容将是“静态的”,因此您无法复制影片剪辑的动画部分。

//store the movie's graphical content in a bitmapdata
var bmd:BitmapData = new BitmapData(movie.width, movie.height);
bmd.draw(movie);

//then create a temporary movie in which you will do the mirroring
var temp:MovieClip = new MovieClip();
temp.addChild(new Bitmap(bmd));

//create the diagonal mask
var _mask:MovieClip = new MovieClip();
with(_mask.graphics) beginFill(0xff0000), lineTo(movie.width, 0), lineTo(movie.width, movie.height), lineTo(0, 0), endFill();
temp.addChild(_mask);
temp.mask = _mask;
//this is the mirroring part
temp.scaleX = temp.scaleY = -1;
addChild(temp);

//then create another bitmapdata for storing the so called "upper-triangle"
//important, that this bitmapdata should be transparent, "true" sets this
var bmd1:BitmapData = new BitmapData(temp.width, temp.height, true, 0x00);
//then do another mirroring transformation
var matrix:Matrix = new Matrix(-1, 0, 0, -1);
matrix.tx = temp.width;
matrix.ty = temp.height;
//draw the visual content on the bitmapdata
bmd1.draw(temp, matrix);

//and finally, on the original bitmapdata, draw the mirrored part
bmd.draw(bmd1);

//and add it to the top layer of the original movie, or whatever you want to do with it
movie.addChild(new Bitmap(bmd));

【讨论】:

    【解决方案2】:

    我能想到的最简单的方法是将影片剪辑旋转 45º 并将上部矩形绘制成反转的下部矩形,然后将位图数据旋转 45º。您可以使用 Matrix(BitmapData.draw 方法中的第二个参数)来绘制它旋转而不是实际旋转任何东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多