0

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?

Robert
  • 7,394
  • 40
  • 45
  • 64
xueling
  • 9
  • 1

1 Answers1

0

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();
}
Yahor Barkouski
  • 1,361
  • 1
  • 5
  • 21