How to output ImageData as a BMP image in Java

63 views Asked by At

How to output ImageData as a BMP image in Java?

I used this code:

ImageLoader imageLoader = new ImageLoader();
imageLoader.save("output.bmp", ImageLoader.TYPE_BMP, new ImageData[]{imageData});

But ImageLoader.TYPE_BMP eported an error stating that the TYPE_BMP could not be found.

May I ask what I should do?

1

There are 1 answers

1
Yahor Barkouski On

SWT's ImageLoader does not support saving images in BMP format directly, so if you need to save an image in BMP, you can use Java's built-in ImageIO class, like:

try {
    BufferedImage image = ImageIO.read(new File("input.jpg"));
    ImageIO.write(image, "bmp", new File("output.bmp"));
} catch (IOException e) {
    e.printStackTrace();
}