JSwiffとは、ピュアJavaでAdobe Flash fileの生成、操作のオープンソースのフレームワークです。

Flashファイルの読み書き機能を提供しています。紹介したTransformJavaSWF2JGeneratorと同じのようなJavaで実装されたフレームワークですが、GoogleやYahooで検索して見ましたが、日本語世界にJSwiffの使用者は多くないようです。

厳しいライセンスGPLを採用するのは、原因の一つかと思います。

Javaには、jpeg、png、gifなど画像ファイルの原寸のサイズを取得することができますが、SWFの形式だったら、取得できないです。JSwiffを使うと、java上でSWFのサイズ取得することを簡単でできます。以下はサンプルソースです。

  1. import java.io.*;
  2. import com.jswiff.*;
  3. import com.jswiff.listeners.*;
  4. import com.jswiff.swfrecords.Rect;
  5.  
  6. public class Test {
  7.     public static void main(String[] args) {
  8.         String path = "****.swf";
  9.         try {
  10.             SWFReader reader = new SWFReader(new FileInputStream(new File(path)));
  11.             SWFDocumentReader docReader = new SWFDocumentReader();
  12.             reader.addListener(docReader);
  13.             reader.read();
  14.             SWFDocument doc = docReader.getDocument();
  15.             Rect rect = doc.getFrameSize();
  16.  
  17.         } catch (Exception e) {
  18.             e.printStackTrace();
  19.         }
  20.     }
  21. }

以下は公式サイトからの「Hello、World」のサンプルです。

  1. private static SWFDocument createDocument() {
  2.     // create a new SWF document
  3.     SWFDocument document    = new SWFDocument();
  4.     // first we define a font for the text
  5.     // get a character ID for the font
  6.     int fontId              = document.getNewCharacterId();
  7.     // use a standard font (e.g. Arial), we don't want to define shapes for each glyph
  8.     DefineFont2 defineFont2 = new DefineFont2(fontId, "Arial", null, null);
  9.     document.addTag(defineFont2);
  10.     // get a character ID for our text
  11.     int textId                    = document.getNewCharacterId();
  12.     // dynamic text is a good way to go, we use DefineEditText for this
  13.     // we don't care about bounds and variables
  14.     DefineEditText defineEditText = new DefineEditText(
  15.         textId, new Rect(0, 0, 0, 0), null);
  16.     // we have set the text bounds to a zero rectangle;
  17.     // to see the whole text, we set the autosize flag
  18.     defineEditText.setAutoSize();
  19.     // assign the font defined above to the text, set font size to 24 px (in twips!)
  20.     defineEditText.setFont(fontId, 20 * 24);
  21.     // set text color to red
  22.     defineEditText.setTextColor(new RGBA(255, 0, 0, 255));
  23.     // don't let viewers mess around with our text
  24.     defineEditText.setReadOnly();
  25.     // finally set the text
  26.     defineEditText.setInitialText("Hello world!");
  27.     document.addTag(defineEditText);
  28.     // place our text at depth 1
  29.     PlaceObject2 placeObject2 = new PlaceObject2(1);
  30.     placeObject2.setCharacterId(textId);
  31.     // place text at position (45; 10) (in twips!)
  32.     placeObject2.setMatrix(new Matrix(20 * 45, 20 * 10));
  33.     document.addTag(placeObject2); // place text
  34.     document.addTag(new ShowFrame()); // show frame
  35.     return document;
  36.   }

リソース

http://www.jswiff.com 公式サイト

メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Monday, 16th February 2009 by admin

Tags: , , ,
Posted in Flash Project | Comments (0) | 3,541 views

Related Posts

Leave a Reply