Actionscript 3 在具有线型笔划的图形上绘制BitmapData.draw()

Actionscript 3 在具有线型笔划的图形上绘制BitmapData.draw(),actionscript-3,Actionscript 3,我使用shape.graphics.drawRoundRect()绘制了一个形状,并应用了lineStyle。我试图使用BitmapData.draw()将该形状捕获为位图,但我遇到了笔划问题。见下文: 如您所见,当使用draw()(和drawWithQuality())时,笔划会被剪裁。线以对象为中心绘制,因此厚度为4(如我在示例中使用的)在形状区域外有2个像素,在形状区域内有2个像素。draw()似乎捕获了从(0,0)到(BitmapData.width,BitmapData.height

我使用
shape.graphics.drawRoundRect()
绘制了一个形状,并应用了
lineStyle
。我试图使用
BitmapData.draw()
将该形状捕获为
位图
,但我遇到了笔划问题。见下文:

如您所见,当使用
draw()
(和
drawWithQuality()
)时,笔划会被剪裁。线以对象为中心绘制,因此厚度为4(如我在示例中使用的)在形状区域外有2个像素,在形状区域内有2个像素。draw()似乎捕获了从(0,0)到(BitmapData.width,BitmapData.height)的所有内容,因此(0,0)左侧和顶部的所有内容都将丢失。我尝试使用clipRect选项进行补偿,但讽刺的是,这恰好平衡了剪裁的边界


知道如何捕获剩余的数据吗?

当然,在我发布问题的第二天,我就想出了方法。使用“绘制”时,必须偏移形状以匹配边界外的线,并补偿线添加到形状中的额外大小

const thickness:int = 4;
const radius:int = 10;
const size:int = 100;

var shape:Shape = new Shape();
shape.graphics.lineStyle( thickness, 0xaaaaaa );
shape.graphics.beginFill( 0xdddddd );
shape.graphics.drawRoundRect( thickness / 2, thickness / 2, size, size, radius, radius );
shape.graphics.endFill();
addChild( shape );

var bmp1:Bitmap = new Bitmap();
bmp1.bitmapData = new BitmapData( size + thickness, size + thickness, true, 0 );
bmp1.x = 310;
bmp1.y = 100;
addChild( bmp1 );
bmp1.bitmapData.draw( shape );
在此处查看结果(您可以忽略剪辑矩形):


作为更一般的解决方案,您可以获得对象在其自身坐标空间中的边界,并使用该边界设置
位图数据的大小,并偏移
绘图()


@利伯罗斯已经试过了。在发布自己的答案后的2天内,您无法将其标记为正确答案。优雅。不需要更改形状的注册点。它是有效的。我喜欢。我将使用我自己的方法,因为它已经实现了,但对我来说这似乎是更好的选择。
import flash.geom.Matrix;
import flash.geom.Rectangle;

const thickness:int = 4;
const radius:int = 10;
const size:int = 100;

var shape:Shape = new Shape();
shape.graphics.lineStyle( thickness, 0xaaaaaa );
shape.graphics.beginFill( 0xdddddd );
shape.graphics.drawRoundRect( 0, 0, size, size, radius, radius );
shape.graphics.endFill();
addChild( shape );

var bounds:Rectangle = shape.getBounds(shape);
var m:Matrix = new Matrix();
m.translate(-bounds.left, -bounds.top);

var bmp1:Bitmap = new Bitmap();
bmp1.bitmapData = new BitmapData( bounds.width, bounds.height, true, 0 );
bmp1.x = 310;
bmp1.y = 100;
addChild( bmp1 );
bmp1.bitmapData.draw( shape, m );