将 Java2D 保存到 SWF (flash) [英] Save Java2D to SWF (flash)

查看:26
本文介绍了将 Java2D 保存到 SWF (flash)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在 Java2D 中绘制的矢量图像的输出保存到 SWF 文件中.有很多很棒的库可以将 java2D 输出保存为 SVG (BATIK) 和 PDF(itext) 之类的东西,但我找不到用于 SWF 的库.有什么想法吗?

I'm trying to save the output of an vector image drawin in Java2D to an SWF file. There are great libraries for saving java2D output as things like SVG (BATIK) and PDF(itext) but I can't find one for SWF. Any ideas?

推荐答案

我刚刚得到了一个使用 SpriteGraphics2D 对象来自 Adobe 的 Flex 3.仅供参考... Flex 3 现在是开源的.

I just got an example to work using the SpriteGraphics2D object from Adobe's Flex 3. FYI... Flex 3 is now open source.

(来自 SpriteGraphics2D javadoc) SpriteGraphics2D 是 Java2D 的 Graphics2D API 的 SWF 特定实现.对此类的调用将转换为可用于构造 SWF 精灵的 TagList.

(from SpriteGraphics2D javadoc) SpriteGraphics2D is a SWF specific implementation of Java2D's Graphics2D API. Calls to this class are converted into a TagList that can be used to construct a SWF Sprite.

我通过查看这两个类发现了这一点 CubicCurveTest.javaSpriteTranscoder.java.

I figured this out by looking at these two classes CubicCurveTest.java and SpriteTranscoder.java.

运行此示例所需的仅有两个 jar 是 swfutils.jar 和 batik-awt-util.jar,它们可以是 在此处下载.

The only two jars needed to run this example are swfutils.jar and batik-awt-util.jar which can be downloaded here.

这是我的示例代码...

Here is my example code...

     // Create the SpriteGraphics2D object
     SpriteGraphics2D g = new SpriteGraphics2D(100, 100);

     // Draw on to the graphics object
     Font font = new Font("Serif", Font.PLAIN, 16);
     g.setFont(font);         
     g.drawString("Test swf", 30, 30);         
     g.draw(new Line2D.Double(5, 5, 50, 60));
     g.draw(new Line2D.Double(50, 60, 150, 40));
     g.draw(new Line2D.Double(150, 40, 160, 10));

     // Create a new empty movie
     Movie m = new Movie();
     m.version = 7;
     m.bgcolor = new SetBackgroundColor(SwfUtils.colorToInt(255, 255, 255));
     m.framerate = 12;
     m.frames = new ArrayList(1);
     m.frames.add(new Frame());
     m.size = new Rect(11000, 8000);

     // Get the DefineSprite from the graphics object
     DefineSprite tag = g.defineSprite("swf-test");

     // Place the DefineSprite on the first frame
     Frame frame1 = (Frame) m.frames.get(0);
     Matrix mt = new Matrix(0, 0);
     frame1.controlTags.add(new PlaceObject(mt, tag, 1, null));

     TagEncoder tagEncoder = new TagEncoder();
     MovieEncoder movieEncoder = new MovieEncoder(tagEncoder);
     movieEncoder.export(m);

     //Write to file
     FileOutputStream fos = new FileOutputStream(new File("/test.swf"));
     tagEncoder.writeTo(fos);

这篇关于将 Java2D 保存到 SWF (flash)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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