如何将SWF/DisplayObject转换为SVG数据?

Art*_*ino 3 flash svg

那里有什么可以将Swf或DisplayObject转换为SVG的东西?

我试图找到一种从swf /矢量形状生成大型JPG的方法.来自AS3的当前jpg export()限制了jpg的大小和分辨率.

所以我想我可以将SVG数据发送到ImageMagick.

谢谢!

阿图尔

Geo*_*nza 6

如果它是一个复杂的SWF,您可能需要使用适当的工具对其进行反编译,然后导入矢量资产并将其转换/重新保存为svg.

如果它只是形状(没有位图/形状),你可以使用真棒AS3SWF库和它的SVGhapeExporter.

这是一个快速的课程:

package {
    import com.bit101.components.*;
    import com.codeazur.as3swf.*;
    import com.codeazur.as3swf.exporters.SVGShapeExporter;
    import com.codeazur.as3swf.tags.*;
    import com.codeazur.as3swf.tags.*;

    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;


    public class SWF2SVG extends Sprite {

        private var swfFile:FileReference;
        private var svgFile:FileReference;
        private var status:Label;
        private var load : PushButton;
        private var save : PushButton;
        private var svg:XML;
        private var filename : String;

        public function SWF2SVG() {
            init();
        }
        private function init():void{
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            drawGUI();
        }
        private function drawGUI() : void {
            var vbox:VBox = new VBox(this);
            var buttons:HBox = new HBox(vbox);
            load = new PushButton(buttons,0,0,"Load SWF",selectSWF);
            save = new PushButton(buttons,0,0,"Save SVG",selectSVG);save.enabled = false;
            status = new Label(buttons,0,0,'load a SWF file');
        }
        private function selectSWF(event:MouseEvent):void{
            swfFile = new FileReference();
            swfFile.addEventListener(Event.SELECT,swfSelected);
            swfFile.addEventListener(Event.COMPLETE,swfLoaded);
            swfFile.browse([new FileFilter("SWF File (*.swf)", "*.swf")]);
        }
        private function selectSVG(event:MouseEvent):void{
            svgFile = new FileReference();
            var bytes:ByteArray = new ByteArray();
            bytes.writeUTFBytes(svg);
            svgFile.save(bytes,filename.replace('.swf','.svg'));
        }
        private function swfSelected(event:Event):void{
            swfFile.load();
            filename = swfFile.name;
            save.enabled = false;
        }
        private function swfLoaded(event:Event):void{
            var bytes:ByteArray = swfFile.data;
            var swf:SWF = new SWF(bytes);
            var svgExporter:SVGShapeExporter = new SVGShapeExporter(swf);
            for (var i:uint = 0; i < swf.tags.length; i++) {
                var tag:ITag = swf.tags[i];
                if (tag is TagDefineShape) TagDefineShape(tag).export(svgExporter);
            }
            svg = svgExporter.svg;
            if(svg != null){
                status.text = "ready! save the SVG file";
                save.enabled = true;
            }else status.text = "no shapes to export found";
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

你可以在这里运行它.

SWF2SVG预览