Reputation: 2714
I'm using PictureCallback to capture an image. And its working fine. But In HTC Desire S its not returning proper data. It returns a corrupted image like the following one
Here is the code that i used
PictureCallback cameraPictureCallbackJpeg = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
// write to local sandbox file system
// outStream =
// CameraDemo.this.openFileOutput(String.format("%d.jpg",
// System.currentTimeMillis()), 0);
// Or write to sdcard
outStream = new FileOutputStream(String.format(
"/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.e("error", "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
I must tell you that I've used other methods to convert the data into a bitmap. Thanks in advance. I'm stuck here. Any help will be appreciated.
Upvotes: 0
Views: 613
Reputation: 1568
It is because you are not using one of the supported image sizes. Here is how you can get those.
Parameters params = camera.getParameters();
List<size> sizes = params.getSupportedPictureSizes();
EDIT: This is how you set the picture size:
Camera.Parameters params = camera.getParameters();
params.setPictureSize(int width, int height);
try {
camera.setParameters(params);
} catch (Exception e) {
Log.e(TAG, "set parameters failed");
}
Upvotes: 1
Reputation: 12367
Nobody promissed you that picture format will be the same on different devices. You have to pay attention to camera settings.
Upvotes: 1