Package org.knowm.xchart
Class BitmapEncoder
- java.lang.Object
-
- org.knowm.xchart.BitmapEncoder
-
public final class BitmapEncoder extends java.lang.ObjectA helper class with static methods for saving Charts as bitmaps
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBitmapEncoder.BitmapFormat
-
Constructor Summary
Constructors Modifier Constructor Description privateBitmapEncoder()Constructor - Private constructor to prevent instantiation
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringaddFileExtension(java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Only adds the extension of the BitmapFormat to the filename if the filename doesn't already have it.static <T extends Chart<?,?>>
byte[]getBitmapBytes(T chart, BitmapEncoder.BitmapFormat bitmapFormat)Generates a byte[] for a given chartstatic <T extends Chart<?,?>>
java.awt.image.BufferedImagegetBufferedImage(T chart)private static java.awt.image.BufferedImagemergeImages(java.util.List<java.awt.image.BufferedImage> images, java.lang.Integer rows, java.lang.Integer cols)static <T extends Chart<?,?>>
voidsaveBitmap(java.util.List<T> charts, java.lang.Integer rows, java.lang.Integer cols, java.io.OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat)Save list of Charts into a given stream.static <T extends Chart<?,?>>
voidsaveBitmap(java.util.List<T> charts, java.lang.Integer rows, java.lang.Integer cols, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Save list of Charts as an image file.static <T extends Chart<?,?>>
voidsaveBitmap(T chart, java.io.OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat)Write a Chart into a given stream.static <T extends Chart<?,?>>
voidsaveBitmap(T chart, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Save a Chart as an image filestatic <T extends Chart<?,?>>
voidsaveBitmapWithDPI(T chart, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat, int DPI)Save a chart as a PNG with a custom DPI.static <T extends Chart<?,?>>
voidsaveJPGWithQuality(T chart, java.lang.String fileName, float quality)Save a Chart as a JPEG fileprivate static voidsetDPI(javax.imageio.metadata.IIOMetadata metadata, int DPI)Sets the metadata correctly
-
-
-
Method Detail
-
addFileExtension
public static java.lang.String addFileExtension(java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Only adds the extension of the BitmapFormat to the filename if the filename doesn't already have it.- Parameters:
fileName-bitmapFormat-- Returns:
- filename (if extension already exists), otherwise;: filename + "." + extension
-
saveBitmap
public static <T extends Chart<?,?>> void saveBitmap(T chart, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws java.io.IOException
Save a Chart as an image file- Parameters:
chart-fileName-bitmapFormat-- Throws:
java.io.IOException
-
saveBitmap
public static <T extends Chart<?,?>> void saveBitmap(T chart, java.io.OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat) throws java.io.IOException
Write a Chart into a given stream. Does not close the target stream automatically at the end of the operation- Parameters:
chart-targetStream-bitmapFormat-- Throws:
java.io.IOException
-
saveBitmap
public static <T extends Chart<?,?>> void saveBitmap(java.util.List<T> charts, java.lang.Integer rows, java.lang.Integer cols, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws java.io.IOException
Save list of Charts as an image file. Function assumes that all charts are the same size (width, height). Number of charts should equal rows multiplied by cols.- Parameters:
charts-rows- number of rowscols- number of columnsfileName-bitmapFormat-- Throws:
java.io.IOException
-
saveBitmap
public static <T extends Chart<?,?>> void saveBitmap(java.util.List<T> charts, java.lang.Integer rows, java.lang.Integer cols, java.io.OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat) throws java.io.IOException
Save list of Charts into a given stream. Does not close the target stream automatically at the end of the operation. Function assumes that all charts are the same size (width, height). Number of charts should equal rows multiplied by cols.- Parameters:
charts-rows- number of rowscols- number of columnstargetStream-bitmapFormat-- Throws:
java.io.IOException
-
saveBitmapWithDPI
public static <T extends Chart<?,?>> void saveBitmapWithDPI(T chart, java.lang.String fileName, BitmapEncoder.BitmapFormat bitmapFormat, int DPI) throws java.io.IOException
Save a chart as a PNG with a custom DPI. The default DPI is 72, which is fine for displaying charts on a computer monitor, but for printing charts, a DPI of around 300 is much better.- Parameters:
chart-fileName-DPI-- Throws:
java.io.IOException
-
setDPI
private static void setDPI(javax.imageio.metadata.IIOMetadata metadata, int DPI) throws javax.imageio.metadata.IIOInvalidTreeExceptionSets the metadata correctly- Parameters:
metadata-DPI-- Throws:
javax.imageio.metadata.IIOInvalidTreeException
-
saveJPGWithQuality
public static <T extends Chart<?,?>> void saveJPGWithQuality(T chart, java.lang.String fileName, float quality) throws java.io.IOException
Save a Chart as a JPEG file- Parameters:
chart-fileName-quality- - a float between 0 and 1 (1 = maximum quality)- Throws:
java.io.IOException
-
getBitmapBytes
public static <T extends Chart<?,?>> byte[] getBitmapBytes(T chart, BitmapEncoder.BitmapFormat bitmapFormat) throws java.io.IOException
Generates a byte[] for a given chart- Parameters:
chart-- Returns:
- a byte[] for a given chart
- Throws:
java.io.IOException
-
getBufferedImage
public static <T extends Chart<?,?>> java.awt.image.BufferedImage getBufferedImage(T chart)
-
mergeImages
private static java.awt.image.BufferedImage mergeImages(java.util.List<java.awt.image.BufferedImage> images, java.lang.Integer rows, java.lang.Integer cols)
-
-