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

📄 baseimageexporter.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.common.export.image;

import java.io.IOException;
import java.io.OutputStream;


/**
 * Base implementation of {@link IImageExporter} in order to provide
 * some basic functionality that every implementation of
 * {@link IImageExporter} would need.  Subclasses need to implement
 * the {@link #exportImage(OutputStream)} method in order to provide
 * the actual export functionality.
 */
public abstract class BaseImageExporter implements IImageExporter {
    private static final String ERROR_NULL_IMAGE_FORMAT = "Image Format is required, and cannot be null.";
    private static final String ERROR_INVALID_WIDTH = "Width must be greater than 0.";
    private static final String ERROR_INVALID_HEIGHT = "Height must be greater than 0.";

    /**
     * Height of the image in pixels
     */
    private int m_height;

    /**
     * Width of the image in pixels
     */
    private int m_width;

    /**
     * Format to encode the image during export.
     */
    private Format m_format;

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.export.image.IImageExporter#exportImage(java.io.OutputStream)
     */
    public abstract int exportImage(OutputStream out) throws IOException;

    public abstract byte[] exportImageToBytes();

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.export.image.IImageExporter#getImageFormat()
     */
    public Format getImageFormat() {
        return m_format;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.export.image.IImageExporter#getImageHeight()
     */
    public int getImageHeight() {
        return m_height;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.export.image.IImageExporter#getImageWidth()
     */
    public int getImageWidth() {
        return m_width;
    }

    /**
     * Sets the Image Height in pixels.   The Image Height should
     * be greater than 0.  The exported image will have the height
     * specified in this method.
     *
     * @param height        Image Height in pixels, must be greater than 0.
     *
     * @throws IllegalArgumentException Thrown if the height is not greater than 0.
     */
    public void setImageHeight(int height) {
        if (height <= 0) {
            throw new IllegalArgumentException(ERROR_INVALID_HEIGHT);
        }

        m_height = height;
    }

    /**
     * Sets the Image Width in pixels.   The Image Width should
     * be greater than 0.  The exported image will have the width
     * specified in this method.
     *
     * @param height        Image Width in pixels, must be greater than 0.
     *
     * @throws IllegalArgumentException Thrown if the width is not greater than 0.
     */
    public void setImageWidth(int width) {
        if (width <= 0) {
            throw new IllegalArgumentException(ERROR_INVALID_WIDTH);
        }

        m_width = width;
    }

    /**
     * Sets the encoding of the image during export.  The exported image
     * will have the encoding specified to this method.
     *
     * @param format Desired encoding format of the image, cannot be
     *                                         <code>null</code>.
     * @throws NullPointerException Thrown if the <code>format</code>
     *                                                                 argument is <code>null</code>.
     */
    public void setImageFormat(Format format) {
        if (format == null) {
            throw new NullPointerException(ERROR_NULL_IMAGE_FORMAT);
        }

        m_format = format;
    }
}

⌨️ 快捷键说明

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