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

📄 chartutilities.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                      int width, int height,
                                      ChartRenderingInfo info,
                                      boolean encodeAlpha,
                                      int compression) throws IOException {

        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        writeChartAsPNG(out, chart, width, height, info, encodeAlpha, compression);
        out.close();

    }

    /**
     * Writes the chart to the output stream in JPEG format.
     *
     * @param out  the output stream.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeChartAsJPEG(OutputStream out,
                                        JFreeChart chart,
                                        int width, int height) throws IOException {

        writeChartAsJPEG(out, DEFAULT_JPEG_QUALITY, chart, width, height, null);

    }

    /**
     * Writes the chart to the output stream in JPEG format.
     *
     * @param out  the output stream.
     * @param quality  the quality setting.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeChartAsJPEG(OutputStream out, float quality,
                                        JFreeChart chart,
                                        int width, int height) throws IOException {

        ChartUtilities.writeChartAsJPEG(out, quality, chart, width, height, null);

    }

    /**
     * Writes the chart to the output stream in JPEG format.
     * <P>
     * This method allows you to pass in a ChartRenderingInfo object, to
     * collect information about the chart dimensions/entities.  You will need
     * this info if you want to create an HTML image map.
     *
     * @param out  the output stream.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     * @param info  the chart rendering info.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeChartAsJPEG(OutputStream out,
                                        JFreeChart chart,
                                        int width, int height,
                                        ChartRenderingInfo info) throws IOException {

        writeChartAsJPEG(out, DEFAULT_JPEG_QUALITY, chart, width, height, info);

    }

    /**
     * Writes the chart to the output stream in JPEG format.
     * <P>
     * This method allows you to pass in a ChartRenderingInfo object, to
     * collect information about the chart dimensions/entities.  You will need
     * this info if you want to create an HTML image map.
     *
     * @param out  the output stream.
     * @param quality  the output quality (0.0f to 1.0f).
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     * @param info  the chart rendering info.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeChartAsJPEG(OutputStream out, float quality,
                                        JFreeChart chart,
                                        int width, int height,
                                        ChartRenderingInfo info) throws IOException {

        BufferedImage chartImage = chart.createBufferedImage(width, height, info);
        ChartUtilities.writeBufferedImageAsJPEG(out, quality, chartImage);

    }

    /**
     * Saves the chart as a JPEG format image file.
     *
     * @param file  the file.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void saveChartAsJPEG(File file,
                                       JFreeChart chart,
                                       int width, int height) throws IOException {

        saveChartAsJPEG(file, DEFAULT_JPEG_QUALITY, chart, width, height, null);

    }

    /**
     * Saves the chart as a JPEG format image file.
     *
     * @param file  the file.
     * @param quality  the JPEG quality setting.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void saveChartAsJPEG(File file, float quality,
                                       JFreeChart chart,
                                       int width, int height) throws IOException {

        saveChartAsJPEG(file, quality, chart, width, height, null);

    }

    /**
     * Saves the chart as a JPEG format image file.
     * <P>
     * This method allows you to pass in a ChartRenderingInfo object, to collect
     * information about the chart dimensions/entities.  You will need this info
     * if you want to create an HTML image map.
     *
     * @param file  the file name.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     * @param info  the chart rendering info.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void saveChartAsJPEG(File file,
                                       JFreeChart chart,
                                       int width, int height,
                                       ChartRenderingInfo info) throws IOException {

        saveChartAsJPEG(file, DEFAULT_JPEG_QUALITY, chart, width, height, info);

    }

    /**
     * Saves the chart as a JPEG format image file.
     * <P>
     * This method allows you to pass in a ChartRenderingInfo object, to collect
     * information about the chart dimensions/entities.  You will need this info
     * if you want to create an HTML image map.
     *
     * @param file  the file name.
     * @param quality  the quality setting.
     * @param chart  the chart.
     * @param width  the image width.
     * @param height  the image height.
     * @param info  the chart rendering info.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void saveChartAsJPEG(File file, float quality,
                                       JFreeChart chart,
                                       int width, int height,
                                       ChartRenderingInfo info
                                       ) throws IOException {

        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        writeChartAsJPEG(out, quality, chart, width, height, info);
        out.close();

    }

    /**
     * Writes the BufferedImage to the output stream in JPEG format.
     * <P>
     * @param out  the output stream.
     * @param image  the buffered image to be written to the OutputStream
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeBufferedImageAsJPEG(OutputStream out, BufferedImage image)
        throws IOException {

        writeBufferedImageAsJPEG(out, 0.75f, image);

    }

    /**
     * Writes the BufferedImage to the output stream in JPEG format.
     * <P>
     * @param out  the output stream.
     * @param quality  the image quality (0.0f to 1.0f).
     * @param image  the buffered image to be written to the OutputStream
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeBufferedImageAsJPEG(OutputStream out, float quality,
                                                BufferedImage image) throws IOException {

        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
        param.setQuality(quality, true);
        encoder.encode(image, param);

    }

    /**
     * Writes the BufferedImage to the output stream in PNG format.
     * <P>
     * @param out  the output stream.
     * @param image  the buffered image to be written to the OutputStream
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeBufferedImageAsPNG(OutputStream out, BufferedImage image)
        throws IOException {

        writeBufferedImageAsPNG(out, image, false, DEFAULT_PNG_COMPRESSION);

    }

    /**
     * Writes the BufferedImage to the output stream in PNG format.
     * <P>
     * @param out  the output stream.
     * @param image  the buffered image to be written to the OutputStream.
     * @param encodeAlpha  encode alpha?
     * @param compression  the compression level.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeBufferedImageAsPNG(OutputStream out, BufferedImage image,
                                               boolean encodeAlpha,
                                               int compression) throws IOException {

        PngEncoder encoder = new PngEncoder(image, encodeAlpha, 0, compression);
        byte[] pngData = encoder.pngEncode();
        out.write(pngData);

    }

    /**
     * Writes an image map to the output stream.
     *
     * @param writer  the writer.
     * @param name  the map name.
     * @param info  the chart rendering info.
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info)
        throws IOException {

        ChartUtilities.writeImageMap(writer, name, info, false);

    }

    /**
     * Writes an image map to the output stream.
     *
     * @param writer  the writer.
     * @param name  the map name.
     * @param info  the chart rendering info.
     * @param useOverLibForToolTips  whether to use OverLIB for tooltips
     *                               (http://www.bosrup.com/web/overlib/).
     *
     * @throws IOException if there are any I/O errors.
     */
    public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info,
                                     boolean useOverLibForToolTips) throws IOException {

        writer.println("<MAP NAME=\"" + name + "\">");
        EntityCollection entities = info.getEntityCollection();
        Iterator iterator = entities.iterator();
        while (iterator.hasNext()) {
            ChartEntity entity = (ChartEntity) iterator.next();
            String area = entity.getImageMapAreaTag(useOverLibForToolTips);
            if (area.length() > 0) {
                writer.println(area);
            }
        }
        writer.println("</MAP>");

    }

}

⌨️ 快捷键说明

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