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

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

问题描述

我试图将Java2D中的矢量图像drawin的输出保存到SWF文件中。有像SVG(BATIK)和PDF(itext)那样保存java2D输出的很好的库,但是我找不到一个用于SWF的库。任何想法?

解决方案

我刚刚拿到了一个使用对象。在这个例子中,SpriteGraphics2D是一个对象,它包含了一个名为SpriteGraphics2D的对象。 Adobe公司的Flex 3 。 FYI ... Flex 3现在是开源的。
$ b


(来自SpriteGraphics2D javadoc) SpriteGraphics2D 是Java2D的Graphics2D API的SWF特定实现。调用这个类被转换成一个TagList,可以用来构造一个SWF Sprite。

我通过查看这些两个类 CubicCurveTest.java SpriteTranscoder.java



运行这个例子的唯一两个jar是swfutils.jar和batik-awt -util.jar可以在这里下载



这是我的示例代码...

$ p $ //创建SpriteGraphics2D对象
SpriteGraphics2D g = new SpriteGraphics2D(100,100);

//绘制到图形对象
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));

//创建一个新的空电影
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);

//从图形对象获取DefineSprite
DefineSprite tag = g.defineSprite(swf-test);

//将DefineSprite放在第一帧
Frame frame1 =(Frame)m.frames.get(0);
矩阵mt =新矩阵(0,0);
frame1.controlTags.add(new PlaceObject(mt,tag,1,null));

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

//写入文件
FileOutputStream fos = new FileOutputStream(new File(/ test.swf));
tagEncoder.writeTo(fos);


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?

解决方案

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

(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.

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

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(闪存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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