public class BMPEncoder
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
static InfoHeader |
createInfoHeader(java.awt.image.BufferedImage img)
Creates an InfoHeader from the source image.
|
static int |
getBitmapSize(int w,
int h,
int bpp)
Calculates the size in bytes of a bitmap with the specified size and colour depth.
|
static int |
getBytesPerLine1(int width)
Calculates the number of bytes per line required for the given width in pixels,
for a 1-bit bitmap.
|
static int |
getBytesPerLine24(int width)
Calculates the number of bytes per line required for the given with in pixels,
for a 24-bit bitmap.
|
static int |
getBytesPerLine4(int width)
Calculates the number of bytes per line required for the given with in pixels,
for a 4-bit bitmap.
|
static int |
getBytesPerLine8(int width)
Calculates the number of bytes per line required for the given with in pixels,
for a 8-bit bitmap.
|
static int |
getColorMapSize(short sBitCount)
Calculates the size in bytes for a colour map with the specified bit count.
|
static void |
write(java.awt.image.BufferedImage img,
java.io.File file)
Encodes and writes BMP data the output file
|
static void |
write(java.awt.image.BufferedImage img,
java.io.OutputStream os)
Encodes and writes BMP data to the output
|
static void |
write1(java.awt.image.Raster raster,
LittleEndianOutputStream out)
Encodes and writes raster data as a 1-bit bitmap.
|
static void |
write24(java.awt.image.Raster raster,
LittleEndianOutputStream out)
Encodes and writes raster data as a 24-bit bitmap.
|
static void |
write32(java.awt.image.Raster raster,
java.awt.image.Raster alpha,
LittleEndianOutputStream out)
Encodes and writes raster data, together with alpha (transparency) data, as a 32-bit bitmap.
|
static void |
write4(java.awt.image.Raster raster,
LittleEndianOutputStream out)
Encodes and writes raster data as a 4-bit bitmap.
|
static void |
write8(java.awt.image.Raster raster,
LittleEndianOutputStream out)
Encodes and writes raster data as an 8-bit bitmap.
|
static void |
writeColorMap(java.awt.image.IndexColorModel icm,
LittleEndianOutputStream out)
Writes the colour map resulting from the source IndexColorModel.
|
static void |
writeFileHeader(int fileSize,
int dataOffset,
LittleEndianOutputStream out)
Writes the file header.
|
public static void write(java.awt.image.BufferedImage img, java.io.File file) throws java.io.IOException
img
- the image to encodefile
- the file to which encoded data will be writtenjava.io.IOException
- if an error occurspublic static void write(java.awt.image.BufferedImage img, java.io.OutputStream os) throws java.io.IOException
img
- the image to encodeos
- the output to which encoded data will be writtenjava.io.IOException
- if an error occurspublic static InfoHeader createInfoHeader(java.awt.image.BufferedImage img)
img
- the source imagepublic static void writeFileHeader(int fileSize, int dataOffset, LittleEndianOutputStream out) throws java.io.IOException
fileSize
- the calculated file size for the BMP data being writtendataOffset
- the calculated offset within the BMP data where the actual bitmap beginsout
- the output to which the file header will be writtenjava.io.IOException
- if an error occurspublic static void writeColorMap(java.awt.image.IndexColorModel icm, LittleEndianOutputStream out) throws java.io.IOException
icm
- the source IndexColorModelout
- the output to which the colour map will be writtenjava.io.IOException
- if an error occurspublic static int getBytesPerLine1(int width)
width
- the width in pixelspublic static int getBytesPerLine4(int width)
width
- the width in pixelspublic static int getBytesPerLine8(int width)
width
- the width in pixelspublic static int getBytesPerLine24(int width)
width
- the width in pixelspublic static int getBitmapSize(int w, int h, int bpp)
w
- the width in pixelsh
- the height in pixelsbpp
- the colour depth (bits per pixel)public static void write1(java.awt.image.Raster raster, LittleEndianOutputStream out) throws java.io.IOException
raster
- the source raster dataout
- the output to which the bitmap will be writtenjava.io.IOException
- if an error occurspublic static void write4(java.awt.image.Raster raster, LittleEndianOutputStream out) throws java.io.IOException
raster
- the source raster dataout
- the output to which the bitmap will be writtenjava.io.IOException
- if an error occurspublic static void write8(java.awt.image.Raster raster, LittleEndianOutputStream out) throws java.io.IOException
raster
- the source raster dataout
- the output to which the bitmap will be writtenjava.io.IOException
- if an error occurspublic static void write24(java.awt.image.Raster raster, LittleEndianOutputStream out) throws java.io.IOException
raster
- the source raster dataout
- the output to which the bitmap will be writtenjava.io.IOException
- if an error occurspublic static void write32(java.awt.image.Raster raster, java.awt.image.Raster alpha, LittleEndianOutputStream out) throws java.io.IOException
raster
- the source raster dataalpha
- the source alpha dataout
- the output to which the bitmap will be writtenjava.io.IOException
- if an error occurspublic static int getColorMapSize(short sBitCount)
sBitCount
- the bit count, which represents the colour depth