3

the following code compress my image or it is not a BMP file:

FileOutputStream fos = new FileOutputStream(imagefile);

bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();

How can I save my image in BMP format?

  • 1
    You should tell us why you think you need a BMP format file. This is a old, heavy, severely windows typed format. What is it you are trying to do ? – Yahel Apr 02 '12 at 16:20
  • I'm curious, why do you think you need a BMP file? PNG is superior in almost every respect. – Mark Ransom Apr 02 '12 at 16:20
  • 2
    @Yahel :-?????? strange question. think that somebody needs for compatiballity with another system. –  Apr 02 '12 at 16:26
  • 2
    @Meehman : The question is not that strange :) Whenever someone asks for something that does not exists although the Android platform is used by hundreds of thousands of developers, you have to ask yourself if the problem is not that the feature does not exists but rather why you think you need it when thousands other developers don't :) You 'think' that its for someone who needs it, aks them the same question I asked you and you might be surprised by the fact that they don't need it. They just don't know :D They could need it though so ask but I bet they don't :) – Yahel Apr 03 '12 at 10:09
  • Answered here: https://stackoverflow.com/questions/22909429/android-save-a-bitmap-to-bmp-file-format – Viktor Brešan Oct 21 '20 at 13:58

2 Answers2

1

There's no built-in encoder for BMP according to this reference. BMP not being an overly complex format, it probably wouldn't be rocket science to write/find a Java implementation.

Rob Pridham
  • 4,780
  • 1
  • 26
  • 38
  • It's up to you - it depends how important BMP is to you. You could convert it outside of Android, e.g. on a server that it's saved to. It's not impossible, just not something that's built in to the API for easy use. – Rob Pridham Apr 02 '12 at 16:32
-2

Hey just give the name to .bmp

Do this:

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
_bitmapScaled.compress(Bitmap.CompressFormat.PNG, 40, bytes);

//you can create a new file name "test.BMP" in sdcard folder.
File f = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "**test.bmp**")

it'll sound that IM JUST FOOLING AROUND but try it once it'll get saved in bmp format..Cheers

Mayank Saini
  • 3,017
  • 24
  • 25
  • 1
    Changing the file extension doesn't actually make it s bitmap image. It just makes it a png with a .bmp file extension. – Rudi Kershaw Jun 11 '14 at 13:29