How To Convert A Bitmap To A Jpeg File In Android?
I have a cropped bitmap image and I need to save it into a jpeg file. Thanks in advance
Solution 1:
Use this:
Bitmapbmp=null;
ByteArrayOutputStreamstream=newByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
for that you can use this:
FileInputStreamfileInputStream=null;
Filefile=newFile("yourfile");
byteArray = newbyte[(int) file.length()];
try {
//convert file into array of bytes
fileInputStream = newFileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
//convert array of bytes into fileFileOutputStreamfileOuputStream=newFileOutputStream("C:\\testing2.txt");
fileOuputStream.write(bFile);
fileOuputStream.close();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
and also for more info go with here
Solution 2:
Try this
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outStream);
Here is a sample Program
Solution 3:
I think this is what you need
bitmap.compress(CompressFormat.JPEG, 90, outputStream);
I hope this will help you.
Post a Comment for "How To Convert A Bitmap To A Jpeg File In Android?"