JSwiffとは、ピュアJavaでAdobe Flash fileの生成、操作のオープンソースのフレームワークです。
Flashファイルの読み書き機能を提供しています。紹介したTransform、JavaSWF2、JGeneratorと同じのようなJavaで実装されたフレームワークですが、GoogleやYahooで検索して見ましたが、日本語世界にJSwiffの使用者は多くないようです。
厳しいライセンスGPLを採用するのは、原因の一つかと思います。
Javaには、jpeg、png、gifなど画像ファイルの原寸のサイズを取得することができますが、SWFの形式だったら、取得できないです。JSwiffを使うと、java上でSWFのサイズ取得することを簡単でできます。以下はサンプルソースです。
- import java.io.*;
- import com.jswiff.*;
- import com.jswiff.listeners.*;
- import com.jswiff.swfrecords.Rect;
- public class Test {
- public static void main(String[] args) {
- String path = "****.swf";
- try {
- SWFReader reader = new SWFReader(new FileInputStream(new File(path)));
- SWFDocumentReader docReader = new SWFDocumentReader();
- reader.addListener(docReader);
- reader.read();
- SWFDocument doc = docReader.getDocument();
- Rect rect = doc.getFrameSize();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
以下は公式サイトからの「Hello、World」のサンプルです。
- private static SWFDocument createDocument() {
- // create a new SWF document
- SWFDocument document = new SWFDocument();
- // first we define a font for the text
- // get a character ID for the font
- int fontId = document.getNewCharacterId();
- // use a standard font (e.g. Arial), we don't want to define shapes for each glyph
- DefineFont2 defineFont2 = new DefineFont2(fontId, "Arial", null, null);
- document.addTag(defineFont2);
- // get a character ID for our text
- int textId = document.getNewCharacterId();
- // dynamic text is a good way to go, we use DefineEditText for this
- // we don't care about bounds and variables
- DefineEditText defineEditText = new DefineEditText(
- textId, new Rect(0, 0, 0, 0), null);
- // we have set the text bounds to a zero rectangle;
- // to see the whole text, we set the autosize flag
- defineEditText.setAutoSize();
- // assign the font defined above to the text, set font size to 24 px (in twips!)
- defineEditText.setFont(fontId, 20 * 24);
- // set text color to red
- defineEditText.setTextColor(new RGBA(255, 0, 0, 255));
- // don't let viewers mess around with our text
- defineEditText.setReadOnly();
- // finally set the text
- defineEditText.setInitialText("Hello world!");
- document.addTag(defineEditText);
- // place our text at depth 1
- PlaceObject2 placeObject2 = new PlaceObject2(1);
- placeObject2.setCharacterId(textId);
- // place text at position (45; 10) (in twips!)
- placeObject2.setMatrix(new Matrix(20 * 45, 20 * 10));
- document.addTag(placeObject2); // place text
- document.addTag(new ShowFrame()); // show frame
- return document;
- }
リソース
・http://www.jswiff.com 公式サイト
メインコンテンツEND ■
Posted on Monday, 16th February 2009 by admin
Tags: JSwiff, SWF, オープンソース, フレームワーク
Posted in Flash Project | Comments (0) | 3,541 views
