⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constructimages.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
字号:
/*
 *  ShowImage.java
 *  Examples
 *
 *  Created by Stuart MacKay on Fri Jul 25 2003.
 *  Copyright (c) 2001-2004 Flagstone Software Ltd. All rights reserved.
 *
 *  This code is distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 *  EXPRESS OR IMPLIED, AND Flagstone HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
 *  WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 *  PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
 */
package com.flagstone.transform.examples;

import com.flagstone.transform.*;
import com.flagstone.transform.util.*;

import java.io.*;

/*
 * This example shows how image can be displayed using the FSImageConstructor.
 *
 * To run this example, type the following on a command line:
 *
 *     java com.flagstone.transform.examples.ConstructImages 
 *         --file image-file [--resultDir path]
 *     
 * where
 *
 *     image-file is the path to a file containing either BMP, PNG or JPEG image.
 *
 *     resultDir is the directory where the Flash file generated by the example 
 *     is written to.
 *
 * The name of the Flash file generated is the same as the image file with the 
 * file extension replaced with a '.swf' suffix.
 */
public class ConstructImages extends Example
{
    private FSImageConstructor imageGenerator = null;  

    public static void main(String[] args)
    {
        new ConstructImages(args);
    }
    
    public ConstructImages(String[] args)
    {
        super(args);
    
        String imageFile = getOption("file", "");
            
        try 
        {
            /* Create the FSImageConstructor object used to generate the object
             * containing the image definition. Initialize it using the name of 
             * the image file passed on the command line when the exanple was run.
             */
            imageGenerator = new FSImageConstructor(imageFile);  
            
            /* Create the name of the Flash file generated using the name of the 
             * font file - adding a '.swf' suffix.
             */
            int first = imageFile.lastIndexOf(File.separatorChar);
            int last = imageFile.lastIndexOf('.');
            
            String fileOut = resultDir + File.separator + imageFile.substring(first, last) + ".swf";
    
            createMovie(imageFile);
            
            movie.encodeToFile(fileOut);
        }
        catch (Exception e)
        {
            /* Several exceptions could be thrown to get to this point. FSImageConstructor
             * will throw a FileNotFoundException, IOException or DataFormatException 
             * if the image format is not support or if an error occurs while
             * loading and decoding the image data.
             * 
             * The FSMovie will throw a FileNotFoundException or IOException if 
             * there is a problem generating the Flash file.
             * 
             * The exceptions are all caught in a single handler to make the code more 
             * readable.
             */
            System.err.println("Cannot create movie for the image: " + imageFile);
        }
     }
    
    public void createMovie(String filename)
    {
        int imageId = movie.newIdentifier();
        int shapeId = movie.newIdentifier();
        
        int xOrigin = imageGenerator.getWidth()/2;
        int yOrigin = imageGenerator.getHeight()/2;
        
        // Generate the image defintion
        FSDefineObject image = imageGenerator.defineImage(imageId);
        
        /*
         * All images must be displayed as a bitmap fill inside a shape. The 
         * FSImageConstructor class generates the shape enclosing the image.
         * If no border is required then the line style may be set to null.
         */
        FSDefineShape3 shape = imageGenerator.defineEnclosingShape(shapeId, imageId, 
            -xOrigin, -yOrigin, new FSSolidLine(20, FSColorTable.black()));
        
        /* 
         * Add all the objects together to create the movie.
         */
        movie.setFrameRate(1.0f);
        movie.setFrameSize(shape.getBounds());
        movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
        movie.add(image);
        movie.add(shape);
        movie.add(new FSPlaceObject2(shapeId, 1, 0, 0));
        movie.add(new FSShowFrame());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -