所以,我有矩形的 bitmapA。我有一个要复制的裁剪区域...
但是,位图与裁剪成一定角度。
如何从不是放置在 x、y 轴上的矩形的位图中复制一个部分?
还是复制自定义形状???
谢谢
所以,我有矩形的 bitmapA。我有一个要复制的裁剪区域...
但是,位图与裁剪成一定角度。
如何从不是放置在 x、y 轴上的矩形的位图中复制一个部分?
还是复制自定义形状???
谢谢
如果需要旋转裁剪矩形,可以使用shortstickdraw
建议的方法裁剪红色区域,如下图:
替代文字 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);
结果如下: alt text http://axly.org/_tmp/stackoverflow/crop_result.png 希望这就是您要找的,否则请提供更多详细信息,甚至更好的是视觉示例。
我能想到的最简单的方法是获取一个临时位图并使用该draw
方法复制有角度的位图,然后从中裁剪。不是最有效的内存,但应该可以。