繁体   English   中英

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

[英]How To Convert a SWF / DisplayObject to SVG data?

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

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

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

谢谢!

阿图尔

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

如果只是形状(没有位图/形状),您可以使用很棒的 AS3SWF 库,它是 SVGhapeExporter。

这是一个快速的 class:

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";
        }

    }

}

你可以在这里运行它。

SWF2SVG 预览

对于服务器使用,您可以使用此 Python package http://pypi.Z23EEEB4347BDD26BFCpy6.B7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM