Taking picture result in a distorted image
I'm using the the Android SDK sample to get an image from the camera. The code below is the only logic I added to the code. Essentially I'm taking the picture converting it to a bitmap and displaying it. Unfortunately this results on a real phone as a distorted image (on the emulator it is just fine)
Any help will be appreciated
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(keyCode){
case KeyEvent.KEYCODE_CAMERA:
mCamera.takePicture(null, null,new PictureCallback(){
@Override
public void onPictureTaken(byte[] data, Camera camera) {
showPicture(data);
}
});
break;
}
return super.onKeyDown(key开发者_运维技巧Code, event);
}
void showPicture(byte[] data) {
if (data != null) {
Bitmap picture = BitmapFactory
.decodeByteArray(data, 0, data.length);
ImageView view = new ImageView(this);
view.setImageBitmap(picture);
this.setContentView(view);
}
}
Found the problem in the surfaceChanged method these lines are to blame
List sizes = parameters.getSupportedPreviewSizes();
if (sizes != null) {
Size optimalSize = getOptimalPreviewSize(sizes, width, height);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
} else {
parameters.setPreviewSize(width, height);
}
Removing them solved all the issue. Now I'll have to make sure that this won't cause new problems
BTW
This Happens on a G2
精彩评论