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

发布于 2024-08-13 00:53:51 字数 137 浏览 4 评论 0原文

所以, 我有 bitmapA ,它是矩形的。我有一个想要复制的裁剪区域...

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

如何从位图中复制不是位于 x、y、轴上的矩形的部分?

或者复制自定义形状???

谢谢

So,
I have bitmapA which is rectangular. I have a crop area I want to copy...

However, the bitmap is at an angle from the crop.

How do I copy a section from a bitmap that isn't a rectangle laid outon the x, y, axis??

Or copy custom shape????

Thanks

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

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

发布评论

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

评论(2

疑心病 2024-08-20 00:53:51

如果需要旋转裁剪矩形,可以使用 draw 方法按照 shortstick 建议裁剪红色区域,如下所示:

替代文本 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);

结果如下:
替代文本 http://axly.org/_tmp/stackoverflow/crop_result.png
希望这就是您正在寻找的内容,否则请提供更多详细信息,甚至更好地提供视觉样本。

If you need to crop a rectangle with rotation, you can use draw method as suggested by shortstick to crop the red area as shown below:

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);

The result is below:
alt text http://axly.org/_tmp/stackoverflow/crop_result.png
Hope that is what you were looking for, otherwise please give more details and, even better, a visual sample.

夏末染殇 2024-08-20 00:53:51

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

simplest way i can think of doing it is getting a temporary bitmap and use the draw method to duplicate the angled bitmap, then crop in from that. not the most memory efficient, but should work.

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