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

📄 fontser.java

📁 使用servlet开发的动态生成GIF图像
💻 JAVA
字号:
import java.io.*;
import java.util.zip.*;
import java.awt.*;
import java.awt.image.*;

/**
 * FontSer. Font serializer (RGB + Descriptor).
 * @version    1.0
 * @author	   S.H.
 * @company    JavaZOOM.
 * @date       01/2000.
 *
 * Use of this source and binary code is permitted only for non-commercial purposes.
 * Modification is allowed with this copyright notice and the following disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
public class fontser
{

  /**
   * Dummy Constructor.
   */
  public void fontser()
  {
  }

  /**
   * Main.
   */
  public static void main(String[] args)
  {
	  /*-- Font info --*/
	  int width = 32;
	  int height = 32;
	  int yspacing = 0;
	  String index = "%!|#$+ '()* ,-./0123456789:;[=]?%ABCDEFGHIJKLMNOPQRSTUVWXYZ&";
	  String filename = "bennyfnt.gif";

	  byte[] compressed = null;
	  Image bitmap = null;
	  int[]	 data = null;
	  int imageW = -1;
	  int imageH = -1;

	  if (args.length < 1) usage();
	  else
	  {
	    /*-- Load bitmap --*/
	    Frame fr = new Frame();
	    MediaTracker aTracker = new MediaTracker(fr);
	    bitmap = (Toolkit.getDefaultToolkit()).getImage(filename);
	    aTracker.addImage(bitmap, 0);
	    try
	    {
			 aTracker.waitForID(0);
	    } catch (Exception e)
	 	  {
			  System.err.println("Cannot load bitmap !");
		  }
	    if (aTracker.isErrorAny()) System.err.println("Cannot load bitmap !");

        /*-- We grab the letter in the font image and put it in a pixel array --*/
        imageW = bitmap.getWidth(fr);
	    imageH = bitmap.getHeight(fr);
	    System.out.println("W = "+imageW+" H= "+imageH);
	    data = new int[imageW*imageH];
        PixelGrabber pg = new PixelGrabber(bitmap, 0, 0, imageW, imageH, data, 0, imageW);
        try
        {
              pg.grabPixels();
        }  catch (InterruptedException e)
           {
				System.err.println("Cannot grab bitmap !");
           }


		byte[] byteArray = new byte[data.length*4];
		try
		{
		    ByteArrayOutputStream baos = new ByteArrayOutputStream();
		    GZIPOutputStream gzos = new GZIPOutputStream((OutputStream)baos);
			int p = 0;
			for (int m=0;m<data.length;m++)
			{
				int tmp  = data[m];
				byteArray[p++] = (byte) ((tmp>>24)&0x000000FF);
				byteArray[p++] = (byte) ((tmp>>16)&0x000000FF);
				byteArray[p++] = (byte) ((tmp>>8)&0x000000FF);
				byteArray[p++] = (byte) (tmp&0x000000FF);
		    }
			gzos.write(byteArray,0,byteArray.length);
			gzos.flush();
			gzos.close();
			compressed = baos.toByteArray();
			baos.close();
		} catch (Exception e)
		  {
			  System.err.println("Compression Error : "+e.getMessage());
		  }

	  	FileOutputStream fos = null;
	  	ObjectOutputStream oos = null;
	  	try
	  	{
	  		fos = new FileOutputStream(args[0]);
			oos = new ObjectOutputStream(fos);
			oos.writeObject(new fontinfo(width, height, yspacing, index, filename,compressed,imageW,imageH));
			oos.flush();
		} catch (InvalidClassException  ice)
		  {
			  System.err.println("Serialization Class Error : "+ice.getMessage());
		  }
		  catch (NotSerializableException  nse)
		  {
			  System.err.println("Serialization Error : "+nse.getMessage());
		  }
		  catch (IOException ioe)
		  {
			  System.err.println("IO Error : "+ioe.getMessage());
		  }
		  catch (SecurityException se)
		  {
			   System.err.println("Security Error : "+se.getMessage());
		  }
		  finally
		  {
			  try
			  {
			  	oos.close();
			  	fos.close();
		  	  } catch (IOException ioex)
		  	    {
					System.err.println("IO closing Error : "+ioex.getMessage());
				}
	  	  }
	  	  System.out.println("OK");
  	  }
  	  System.exit(0);
  }

  public static void usage()
  {
	  System.err.println("Usage : fontser <filename>\n");
  }

}

⌨️ 快捷键说明

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