1 flash crop bitmap actionscript-3
所以,我的bitmapA是矩形的.我有一个我要复制的裁剪区域......
但是,位图与裁剪成一定角度.
如何从位图复制一个部分,该部分不是在x,y轴上布置的矩形?
或复制自定义形状????
谢谢
如果需要使用旋转裁剪矩形,可以使用短杆draw建议的方法裁剪红色区域,如下所示:
alt text http://axly.org/_tmp/stackoverflow/crop_sample.png
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);
Run Code Online (Sandbox Code Playgroud)
结果如下: 替代文字http://axly.org/_tmp/stackoverflow/crop_result.png 希望这是您正在寻找的,否则请提供更多细节,甚至更好的视觉样本.