I looked at a bunch of other stack answers regarding bad images from an Android camera, but they all look from people who grabbed a thumbnail and then scaled it.
My problem is that even the image stored in the library comes out with very poor quality. It comes out with dull colors and more pixelated.
Here is my callback where I save the image in the library. Do you see why I lose image quality when I save it?
Here is the callback
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
MediaScannerConnection.scanFile(getBaseContext(), new String[]{pictureFile.getPath()}, new String[]{"image/png"}, null);
This is where I get outputMediaFile
private static File getOutputMediaFile(int type){
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "PumpUp");
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE){
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".png");
Log.d(DEBUG_TAG,mediaStorageDir.getPath() + File.separator + "IMG_"+ timeStamp + ".png");
} else if(type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
UPDATE:
The bitmap data gives me a width and height of 320. Do you know why this has decreased?
UPDATE 2:
This code prints 320W 240H
private Camera.PictureCallback mPicture = new Camera.PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
Bitmap imageBitmap = BitmapFactory.decodeByteArray(data,0,data.length);
Log.d(DEBUG_TAG,imageBitmap.getWidth() + " h " + imageBitmap.getHeight());
}
, ?