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

📄 ppmformatter.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/image/PPMFormatter.java,v $// $RCSfile: PPMFormatter.java,v $// $Revision: 1.2.2.2 $// $Date: 2005/08/09 19:18:31 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.image;import java.awt.image.BufferedImage;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.util.Properties;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * A simple formatter to create PPM images. * <P> * I got a simple definition of a PPM image an wrote something to make * that. XV complains about the P3 image, but still draws it. No * complaints for the P6. */public class PPMFormatter extends AbstractImageFormatter {    public static final String RawBitsProperty = "rawbits";    public static final String regularMagicNumber = "P3";    public static final String rawbitsMagicNumber = "P6";    public static final int HEADER_BUFFER_SIZE = 50; // approximate,                                                     // no big deal    public static final int MAX_COLOR_VALUE = 255; // I guess    protected boolean rawbits;    public PPMFormatter() {}    public void setProperties(String prefix, Properties props) {        rawbits = PropUtils.booleanFromProperties(props, (prefix == null ? ""                : prefix)                + RawBitsProperty, true);    }    public ImageFormatter makeClone() {        PPMFormatter formatter = new PPMFormatter();        formatter.rawbits = rawbits;        return formatter;    }    public boolean getRawbits() {        return rawbits;    }    public void setRawbits(boolean rb) {        rawbits = rb;    }    public byte[] formatImage(BufferedImage bi) {        int height = bi.getHeight();        int width = bi.getWidth();        int[] data = new int[width * height];        bi.getRGB(0, 0, width, height, data, 0, width);        ByteArrayOutputStream baos = new ByteArrayOutputStream();        DataOutputStream dos = new DataOutputStream(baos);        try {            int pixel, count, i, lastCount;            if (!rawbits) {                dos.writeBytes(regularMagicNumber);                dos.writeBytes(" " + width);                dos.writeBytes(" " + height);                dos.writeBytes(" " + MAX_COLOR_VALUE + "\n");                count = 0; // Keep lines less that 70 characters long                // Keep track of the number of characters added per                // pass                lastCount = 0;                Debug.output("PPMFormatter: Header is " + dos.size() + " bytes");                Debug.output("PPMFormatter: Height = " + height);                Debug.output("PPMFormatter: Width = " + width);                Debug.output("PPMFormatter: data length = " + data.length);                for (i = 0; i < data.length; i++) {                    pixel = data[i];                    int r = (pixel >>> 16) & 0x000000FF;                    int g = (pixel >>> 8) & 0x000000FF;                    int b = (pixel) & 0x000000FF;                    dos.writeBytes(" " + r);                    dos.writeBytes(" " + g);                    dos.writeBytes(" " + b);                    if (count > 57) {                        dos.writeBytes("\n");                        count = 0;                    } else {                        count += dos.size() - lastCount;                    }                    lastCount = dos.size();                }                Debug.output("PPMFormatter: after data, size is " + dos.size());            } else {                dos.writeBytes(rawbitsMagicNumber);                dos.writeBytes(" " + width);                dos.writeBytes(" " + height);                dos.writeBytes(" " + MAX_COLOR_VALUE + "\n");                for (i = 0; i < data.length; i++) {                    pixel = data[i];                    dos.writeByte(pixel >>> 16);                    dos.writeByte(pixel >>> 8);                    dos.writeByte(pixel);                }            }            return baos.toByteArray();        } catch (java.io.IOException ioe) {            System.err.println("PPMFormatter caught IOException formatting image!");            return new byte[0];        }    }    /**     * Get the Image Type created by the ImageFormatter. These     * responses should adhere to the OGC WMT standard format labels.     * Some are listed in the WMTConstants interface file.     */    public String getFormatLabel() {        return WMTConstants.IMAGEFORMAT_PPM;    }}

⌨️ 快捷键说明

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