I am trying to take a picture using an Android camera. I have a requirement to capture an image of 1600 (w) x 1200 (h) (a third-party requirement). My code seems to work fine for many phone cameras, but setPictureSize crashes on some phones (Samsung Galaxy S4, Samsung Galaxy Note) and causes a series of images on others (Nexus 7 tablet). At least the Nexus size that I wish is displayed in the getSupportPictureSizes list.
I tried to indicate the orientation, but that did not help. Shooting with the default image size works fine.
Here is an example of bands:

For my image capture, I have a requirement of 1600x1200, jpg, 30% compression, so I take a JPG file.
I think I have three options: 1) Learn how to capture a size of 1600x1200 without glitches or stripes, or 2) Look at how to resize the default image size to JPG, which is 1600x1200. 3) Something else that I do not know.
I found several other posts that have similar problems, but not exactly the same. I am on my second day of trying, but I cannot find a solution. Here is one message that is close:
A camera image for a bitmap results in a damaged image (none of the suggestions helped me)
Here is a section of my code that worked fine until I came across S4 / Note / Nexus 7. At the moment, I have added some code for debugging:
Camera.Parameters parameters = mCamera.getParameters();
Camera.Size size = getBestPreviewSize(width, height, parameters);
if (size != null) {
int pictureWidth = 1600;
int pictureHeight = 1200;
Camera.Size test = parameters.getPictureSize();
List<Camera.Size> testSizes = parameters.getSupportedPictureSizes();
for ( int i = 0; i < testSizes.size(); i++ ) {
test = testSizes.get(i);
}
test = testSizes.get(3);
pictureWidth = test.width;
pictureHeight = test.height;
parameters.setPictureFormat(ImageFormat.JPEG);
parameters.setPictureSize(pictureWidth, pictureHeight);
parameters.setJpegQuality(30);
parameters.setPreviewSize(size.width, size.height);
try {
mCamera.stopPreview();
mCamera.setParameters(parameters);
didConfig = true;
catch(Exception e) {
}
}
Here is the section of my code that saves the jpg file:
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
if ( data.length > 0 ) {
String fileName = "image.jpg";
File file = new File(getFilesDir(), fileName);
String filePath = file.getAbsolutePath();
boolean goodWrite = false;
try {
OutputStream os = new FileOutputStream(file);
os.write(data);
os.close();
goodWrite = true;
} catch (IOException e) {
goodWrite = false;
}
if ( goodWrite ) {
} else {
}
}
Log.d(TAG, "onPictureTaken - jpeg");
}
};
, , . , ( API 8 )! , .
!
: :
Camera.Parameters getSupportedPictureSizes, , , , , . .
, :
BitmapFactory.Options options = new BitmapFactory.Options();;
options.inPurgeable = true;
Bitmap original = BitmapFactory.decodeByteArray(input , 0, input.length, options);
Bitmap resized = Bitmap.createScaledBitmap(original, 1600, 1200, true);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 30, blob);
original.recycle();
resized.recycle();
byte[] desired = blob.toByteArray();
jpg .