How to convert bitmap to jpeg file on Android?

I'm a little lost here. I need to convert a bitmap from a cropped image to a .jpeg file. I looked at other related issues, but none of them were relative to mine. (most of them were returned as a file in a bitmap)

Thanks in advance

ps. Android development for the first time

+16
android file bitmap jpeg
source share
3 answers

Use this:

Bitmap bmp = null; ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); 

for this you can use this:

 FileInputStream fileInputStream = null; File file = new File("yourfile"); byteArray = new byte[(int) file.length()]; try { //convert file into array of bytes fileInputStream = new FileInputStream(file); fileInputStream.read(bFile); fileInputStream.close(); //convert array of bytes into file FileOutputStream fileOuputStream = new FileOutputStream("C:\\testing2.txt"); fileOuputStream.write(bFile); fileOuputStream.close(); System.out.println("Done"); } catch (Exception e) { e.printStackTrace(); } 

and for more information go here

+27
source share

try it

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

Here is an example program

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

+3
source share

I think this is what you need.

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

Hope this helps you.

+1
source share

All Articles