0

一部の SVG データを PNG にラスタライズしようとしていますが、うまくいきません。誰かが私が間違っていることを教えてもらえますか?

このコードの BitmapData オブジェクトにはデータが含まれていないようです。

 var color:uint = Math.floor( (Math.random() * 0xFFFF00) + 0x0000FF);
 var graphic:Graphic = new Graphic();
 graphic.graphics.beginFill(color);

 var pathData:String = "M 0 0 L 0 40 L 40 40 L 40 40 Z";
 var path:Path = new Path();
 path.data = pathData;
 path.x =0;
 path.y=0;
 path.width = 40;
 path.height = 40;
 path.stroke=new SolidColorStroke(100);
 path.fill=new SolidColor(100);
 path.winding = GraphicsPathWinding.EVEN_ODD;
 graphic.addElement(path);
 graphic.width = 40;
 graphic.height = 40;
 graphic.validateNow();
 var FillColor = 0x00000000;
 var bitMapData:BitmapData = new BitmapData(graphic.width,graphic.height, true, FillColor);
 bitMapData.draw(graphic);

しかし、このコードは次のことを行います。

var graphic:Graphic = new Graphic();
graphic.graphics.beginFill(color);
var width:Number = Math.floor(Math.random() * (MAXWIDTH-MINWIDTH)) + MINWIDTH;
var height:Number = Math.floor(Math.random() * (MAXHEIGHT-MINHIEGHT)) + MINHIEGHT;
var radius:Number = Math.floor( (Math.random()*(MAXRADIUS-MINRADIUS)))+MINRADIUS;
width = height = radius*2;
graphic.graphics.drawCircle(radius, radius,radius );
graphic.graphics.endFill();

var FillColor = 0x00000000;
var bitMapData:BitmapData = new BitmapData(graphic.width,graphic.height, true, FillColor);
bitMapData.draw(graphic);

私が行った場合:

 var temp:Graphic = new Graphic();
    temp.graphics.beginFill(0x000000);
    temp.graphics.drawRect(0,0,width/2, height/2);
    temp.graphics.endFill();
    sprite.graphics.drawRect(0,0,width, height);
    sprite.addElement(temp);

どちらの長方形もキャンバスに描画しますが、

BitMapData.draw(sprite);

トップレベルのスプライトのみを表示します。

4

1 に答える 1

0

だから私はそれを理解しました。パスは、BeforeDraw()、Draw()、および EndDraw() を使用して、塗りと線の操作を実行します。問題は、パスがキャンバスにレンダリングされるまで、これらの関数が呼び出されないことです。そこで、パス クラスを拡張し、EndDraw() 関数をオーバーライドしました。この関数では、イベントをディスパッチしました。次に、イベントをキャッチすると、パス (現在入力済み) から DisplayObject を取得し、そのオブジェクトを BitmapData() に渡すことができます。

于 2015-02-26T23:43:40.670 に答える