How can I convert a BufferedImage object to a BMP file?

Sandip Chitale

The BufferedImage allows you to get at the raw data associated with the image using the

BufferedImage bi = //....;
int rgb[] = bi.getRGB(int startX,
                    int startY,
                    int w,
                    int h,
                    int[] rgbArray,
                    int offset,
                    int scansize);
// The returned int array is in the format -
// pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
// Now convert this data into the .bmp format

The information about .bmp file format can be found here -