My app uses the Camera to take high-res images, which are then jpeg
compressed and sent over the network. Initially I relied on the jpeg
quality setting in the Camera API:
final Camera.Parameters params = mCamera.getParameters();
params.setPictureFormat(PixelFormat.JPEG);
params.setJpegQuality(mQuality);
mCamera.setParameters(params);
...but the results are highly inconsistent. The size of the resulting jpeg
file can vary by a factor of four, even when the scene, dimensions and jpeg
quality are held constant. I gather this is because the compression is
performed in firmware and some devices do a better job than others. As a
workaround, I tried using Android's Bitmap classes to perform the
compression in a way that would be consistent across devices:
public static byte[] compress(byte[] data, CompressFormat format, int
quality) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Bitmap bm = BitmapFactory.decodeByteArray(data, 0,
data.length);
try {
bm.compress(format, quality, baos);
} finally {
bm.recycle();
}
return baos.toByteArray();
}
When this works it works great, but it results in OutOfMemoryErrors when
the dimensions are sufficiently large. Certainly some of the resolutions
supported by newer cameras are too large for this method to work reliably.
So my questions are:
1. Is there a way to make the Camera API perform jpeg compression in a way
that's consistent across devices?
2. If not, then are is there a way in which I can use the Bitmap classes
differently so as to avoid or mitigate the OutOfMemoryErrors?
3. If not, then can anyone recommend a different method of achieving
consistent jpeg compression (possibly via third-party jar)? Something
that's pure java and does byte[] -> byte[] conversion (without having to
materialize the image in a intermediate form) would be ideal.
Thanks in advance.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en