Package org.knowm.xchart
Class BitmapEncoder
java.lang.Object
org.knowm.xchart.BitmapEncoder
public final class BitmapEncoder extends Object
A helper class with static methods for saving Charts as bitmaps
- Author:
- timmolter
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBitmapEncoder.BitmapFormat -
Method Summary
Modifier and Type Method Description static StringaddFileExtension(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 org.knowm.xchart.internal.chartpart.Chart<?, ?>>
byte[]getBitmapBytes(T chart, BitmapEncoder.BitmapFormat bitmapFormat)Generates a byte[] for a given chartstatic <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
BufferedImagegetBufferedImage(T chart)static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveBitmap(List<T> charts, Integer rows, Integer cols, OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat)Save list of Charts into a given stream.static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveBitmap(List<T> charts, Integer rows, Integer cols, String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Save list of Charts as an image file.static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveBitmap(T chart, OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat)Write a Chart into a given stream.static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveBitmap(T chart, String fileName, BitmapEncoder.BitmapFormat bitmapFormat)Save a Chart as an image filestatic <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveBitmapWithDPI(T chart, String fileName, BitmapEncoder.BitmapFormat bitmapFormat, int DPI)Save a chart as a PNG with a custom DPI.static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>>
voidsaveJPGWithQuality(T chart, String fileName, float quality)Save a Chart as a JPEG file
-
Method Details
-
addFileExtension
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 org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveBitmap(T chart, String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws IOExceptionSave a Chart as an image file- Parameters:
chart-fileName-bitmapFormat-- Throws:
IOException
-
saveBitmap
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveBitmap(T chart, OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat) throws IOExceptionWrite a Chart into a given stream. Does not close the target stream automatically at the end of the operation- Parameters:
chart-targetStream-bitmapFormat-- Throws:
IOException
-
saveBitmap
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveBitmap(List<T> charts, Integer rows, Integer cols, String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws IOExceptionSave 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:
IOException
-
saveBitmap
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveBitmap(List<T> charts, Integer rows, Integer cols, OutputStream targetStream, BitmapEncoder.BitmapFormat bitmapFormat) throws IOExceptionSave 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:
IOException
-
saveBitmapWithDPI
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveBitmapWithDPI(T chart, String fileName, BitmapEncoder.BitmapFormat bitmapFormat, int DPI) throws IOExceptionSave 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:
IOException
-
saveJPGWithQuality
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> void saveJPGWithQuality(T chart, String fileName, float quality) throws IOExceptionSave a Chart as a JPEG file- Parameters:
chart-fileName-quality- - a float between 0 and 1 (1 = maximum quality)- Throws:
IOException
-
getBitmapBytes
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> byte[] getBitmapBytes(T chart, BitmapEncoder.BitmapFormat bitmapFormat) throws IOExceptionGenerates a byte[] for a given chart- Parameters:
chart-- Returns:
- a byte[] for a given chart
- Throws:
IOException
-
getBufferedImage
public static <T extends org.knowm.xchart.internal.chartpart.Chart<?, ?>> BufferedImage getBufferedImage(T chart)
-