28

I have a cropped bitmap image and I need to save it into a jpeg file.

How do I convert it from a bitmap to a jpeg file in Android?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Carlo Matulessy
  • 975
  • 1
  • 13
  • 27

2 Answers2

7

Try this

bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outStream);

Here is a sample Program

compressing-a-bitmap-to-jpg-format-android

Karthi
  • 756
  • 4
  • 16
3

I think this is what you need

bitmap.compress(CompressFormat.JPEG, 90, outputStream);

I hope this will help you.

Pooja Sangle
  • 331
  • 2
  • 10
  • 2
    Good point. To those who don't know how to use this approach: 1. `ByteArrayOutputStream out = new ByteArrayOutputStream();` 2. `bitmap.compress(CompressFormat.JPEG, 90, out);` 3. write byte[] into file or use it anywhere else (for example you can show it in ImageView with the help of Glide lib) – Kirill Karmazin Oct 31 '18 at 21:27