Flash as3从位图中复制自定义形状

Flash as3从位图中复制自定义形状,flash,actionscript-3,bitmap,crop,Flash,Actionscript 3,Bitmap,Crop,所以, 我有一个矩形的位图。我要复制一个作物区域 但是,位图与裁剪成一定角度 如何从不是x、y、轴上矩形的位图复制截面 还是复制自定义形状 谢谢我能想到的最简单的方法是获得一个临时位图,然后使用绘制方法复制角度位图,然后从中裁剪。不是最有效的内存,但应该可以工作。我能想到的最简单的方法是获取一个临时位图,并使用绘制方法复制角度位图,然后从中裁剪。不是最有效的内存,但应该可以工作。如果需要剪切带旋转的矩形,可以使用短棒建议的方法剪切红色区域,如下所示: 结果如下: 希望这就是您想要的,否则请提供

所以, 我有一个矩形的位图。我要复制一个作物区域

但是,位图与裁剪成一定角度

如何从不是x、y、轴上矩形的位图复制截面

还是复制自定义形状


谢谢

我能想到的最简单的方法是获得一个临时位图,然后使用
绘制
方法复制角度位图,然后从中裁剪。不是最有效的内存,但应该可以工作。

我能想到的最简单的方法是获取一个临时位图,并使用
绘制方法复制角度位图,然后从中裁剪。不是最有效的内存,但应该可以工作。

如果需要剪切带旋转的矩形,可以使用短棒建议的方法剪切红色区域,如下所示:

结果如下:
希望这就是您想要的,否则请提供更多详细信息,更好的是,提供一个可视示例。

如果您需要剪切带旋转的矩形,您可以使用短棒建议的方法剪切红色区域,如下所示:

结果如下: 希望这就是你想要的,否则请提供更多的细节,更好的是,一个视觉样品

var crop_rect:Rectangle = new Rectangle(0,0,64,57);//size of the segment to copy
var crop_point:Point = new Point(40,50);//relative position of the crop from the top/left corner of the image
var crop_angle:Number = Math.PI / 12;//angle of the crop relative to image in radians (clockwise)

//transformation [tx,ty] parameters representing shift after rotation
var dA:Number = Math.atan(crop_point.y / crop_point.x) - crop_angle;
var tX:Number = crop_point.length * Math.cos(dA);
var tY:Number = crop_point.length * Math.sin(dA);

var scaleMatrix:Matrix = new Matrix(Math.cos( -  crop_angle),Math.sin( -  crop_angle), -  Math.sin( -  crop_angle),Math.cos( -  crop_angle), -  tX, -  tY);
var colorTransform:ColorTransform = new ColorTransform();//no colour transformation needed

//copy selected segment after rotation and shift to match the size of the crop
var result_bitmap = new BitmapData(crop_rect.width,crop_rect.height);
result_bitmap.draw(source_img, scaleMatrix , colorTransform, null, crop_rect, true);
var result_img:Bitmap = new Bitmap(result_bitmap);