如何将SWF / DisplayObject转换为SVG数据? [英] How To Convert a SWF / DisplayObject to SVG data?

查看:150
本文介绍了如何将SWF / DisplayObject转换为SVG数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

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



谢谢!


解决方案

如果是复杂的SWF,使用合适的工具对其进行反编译,然后导入矢量素材并将其保存为svg。
$ b

如果只是形状(无位图/形状),您可以使用真棒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。*;
导入flash.events。*;
import flash.net。*;
import flash.utils。*;


public class SWF2SVG extends Sprite {
$ b $ 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(按钮,0,0,加载SWF,selectSWF);
save = new PushButton(buttons,0,0,Save SVG,selectSVG); save.enabled = false;
status = new Label(按钮,0,0,'加载SWF文件');

private function selectSWF(event:MouseEvent):void {
swfFile = new FileReference();
swfFile.addEventListener(Event.SELECT,swfSelected);
swfFile.addEventListener(Event.COMPLETE,swfLoaded);
swfFile.browse([新的FileFilter(SWF文件(* .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 =新的SWF(字节);
var svgExporter:SVGShapeExporter = new SVGShapeExporter(swf);
for(var i:uint = 0; i< swf.tags.length; i ++){
var tag:ITag = swf.tags [i];
if(tag是TagDefineShape)TagDefineShape(tag).export(svgExporter);
}
svg = svgExporter.svg;
if(svg!= null){
status.text =ready!保存SVG文件;
save.enabled = true;
} else status.text =找不到要导出的图形;




code


$ b <你可以运行这里




Anything out there that can transform a Swf or DisplayObject into an SVG?

Im trying to find a way to generate a large Sized JPG from a swf/vector shape. The current jpg export() from AS3 has limits to jpg size and resolution.

so i figured i can just send SVG data to ImageMagick.

thanks!

artur

解决方案

If it's a complex SWF, you might need to decompile it using a proper tool and then import the vector assets and convert/re save them as svg.

If it's just shapes (no bitmaps/shapes), you can use the awesome AS3SWF library and it's SVGhapeExporter.

Here's a quick 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";
        }

    }

}

You can run it here.

这篇关于如何将SWF / DisplayObject转换为SVG数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆