Package daevil.iconexe
Class WriteBMP32
- java.lang.Object
-
- daevil.iconexe.WriteBMP32
-
public class WriteBMP32 extends java.lang.ObjectFor writing 32 bit BMP (imageio won't), credit to Ian McDonagh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWriteBMP32.InfoHeaderstatic classWriteBMP32.LittleEndianOutputStream
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static WriteBMP32.InfoHeadercreateInfoHeader(java.awt.image.BufferedImage img)Creates an InfoHeader from the source image.static intgetBitmapSize(int w, int h, int bpp)Calculates the size in bytes of a bitmap with the specified size and colour depth.static intgetBytesPerLine1(int width)Calculates the number of bytes per line required for the given width in pixels, for a 1-bit bitmap.static intgetBytesPerLine24(int width)Calculates the number of bytes per line required for the given with in pixels, for a 24-bit bitmap.static intgetBytesPerLine4(int width)Calculates the number of bytes per line required for the given with in pixels, for a 4-bit bitmap.static intgetBytesPerLine8(int width)Calculates the number of bytes per line required for the given with in pixels, for a 8-bit bitmap.static intgetColorMapSize(short sBitCount)Calculates the size in bytes for a colour map with the specified bit count.static voidwrite(java.awt.image.BufferedImage img, java.io.File file)Encodes and writes BMP data the output filestatic voidwrite(java.awt.image.BufferedImage img, java.io.OutputStream os)Encodes and writes BMP data to the outputstatic voidwrite1(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out)Encodes and writes raster data as a 1-bit bitmap.static voidwrite24(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out)Encodes and writes raster data as a 24-bit bitmap.static voidwrite32(java.awt.image.Raster raster, java.awt.image.Raster alpha, WriteBMP32.LittleEndianOutputStream out)Encodes and writes raster data, together with alpha (transparency) data, as a 32-bit bitmap.static voidwrite4(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out)Encodes and writes raster data as a 4-bit bitmap.static voidwrite8(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out)Encodes and writes raster data as an 8-bit bitmap.static voidwriteColorMap(java.awt.image.IndexColorModel icm, WriteBMP32.LittleEndianOutputStream out)Writes the colour map resulting from the source IndexColorModel.static voidwriteFileHeader(int fileSize, int dataOffset, WriteBMP32.LittleEndianOutputStream out)Writes the file header.
-
-
-
Method Detail
-
write
public static void write(java.awt.image.BufferedImage img, java.io.File file) throws java.io.IOExceptionEncodes and writes BMP data the output file- Parameters:
img- the image to encodefile- the file to which encoded data will be written- Throws:
java.io.IOException- if an error occurs
-
write
public static void write(java.awt.image.BufferedImage img, java.io.OutputStream os) throws java.io.IOExceptionEncodes and writes BMP data to the output- Parameters:
img- the image to encodeos- the output to which encoded data will be written- Throws:
java.io.IOException- if an error occurs
-
createInfoHeader
public static WriteBMP32.InfoHeader createInfoHeader(java.awt.image.BufferedImage img)
Creates an InfoHeader from the source image.- Parameters:
img- the source image- Returns:
- the resultant InfoHeader structure
-
writeFileHeader
public static void writeFileHeader(int fileSize, int dataOffset, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionWrites the file header.- Parameters:
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 written- Throws:
java.io.IOException- if an error occurs
-
writeColorMap
public static void writeColorMap(java.awt.image.IndexColorModel icm, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionWrites the colour map resulting from the source IndexColorModel.- Parameters:
icm- the source IndexColorModelout- the output to which the colour map will be written- Throws:
java.io.IOException- if an error occurs
-
getBytesPerLine1
public static int getBytesPerLine1(int width)
Calculates the number of bytes per line required for the given width in pixels, for a 1-bit bitmap. Lines are always padded to the next 4-byte boundary.- Parameters:
width- the width in pixels- Returns:
- the number of bytes per line
-
getBytesPerLine4
public static int getBytesPerLine4(int width)
Calculates the number of bytes per line required for the given with in pixels, for a 4-bit bitmap. Lines are always padded to the next 4-byte boundary.- Parameters:
width- the width in pixels- Returns:
- the number of bytes per line
-
getBytesPerLine8
public static int getBytesPerLine8(int width)
Calculates the number of bytes per line required for the given with in pixels, for a 8-bit bitmap. Lines are always padded to the next 4-byte boundary.- Parameters:
width- the width in pixels- Returns:
- the number of bytes per line
-
getBytesPerLine24
public static int getBytesPerLine24(int width)
Calculates the number of bytes per line required for the given with in pixels, for a 24-bit bitmap. Lines are always padded to the next 4-byte boundary.- Parameters:
width- the width in pixels- Returns:
- the number of bytes per line
-
getBitmapSize
public static int getBitmapSize(int w, int h, int bpp)Calculates the size in bytes of a bitmap with the specified size and colour depth.- Parameters:
w- the width in pixelsh- the height in pixelsbpp- the colour depth (bits per pixel)- Returns:
- the size of the bitmap in bytes
-
write1
public static void write1(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionEncodes and writes raster data as a 1-bit bitmap.- Parameters:
raster- the source raster dataout- the output to which the bitmap will be written- Throws:
java.io.IOException- if an error occurs
-
write4
public static void write4(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionEncodes and writes raster data as a 4-bit bitmap.- Parameters:
raster- the source raster dataout- the output to which the bitmap will be written- Throws:
java.io.IOException- if an error occurs
-
write8
public static void write8(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionEncodes and writes raster data as an 8-bit bitmap.- Parameters:
raster- the source raster dataout- the output to which the bitmap will be written- Throws:
java.io.IOException- if an error occurs
-
write24
public static void write24(java.awt.image.Raster raster, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionEncodes and writes raster data as a 24-bit bitmap.- Parameters:
raster- the source raster dataout- the output to which the bitmap will be written- Throws:
java.io.IOException- if an error occurs
-
write32
public static void write32(java.awt.image.Raster raster, java.awt.image.Raster alpha, WriteBMP32.LittleEndianOutputStream out) throws java.io.IOExceptionEncodes and writes raster data, together with alpha (transparency) data, as a 32-bit bitmap.- Parameters:
raster- the source raster dataalpha- the source alpha dataout- the output to which the bitmap will be written- Throws:
java.io.IOException- if an error occurs
-
getColorMapSize
public static int getColorMapSize(short sBitCount)
Calculates the size in bytes for a colour map with the specified bit count.- Parameters:
sBitCount- the bit count, which represents the colour depth- Returns:
- the size of the colour map, in bytes if sBitCount is less than or equal to 8, otherwise 0 as colour maps are only used for bitmaps with a colour depth of 8 bits or less.
-
-