Reputation: 4594
I have the following problem:I have an app where I'm using the camera of the android device.
I have built my own camera.The BIG problem
is that when the preview starts all the image looks resized.Every object looks longer, larger...
in surfaceChanged()
method I've done this:
List<Size> previews = p.getSupportedPreviewSizes();
I looped this list
previews
but I haven't found a better size for my preview.
The list
previews
has the size equal to 7 but nne of this items make my image look better!!
Here is how my method looks like:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Log.e(TAG, "surfaceChanged");
if (mPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters p = mCamera.getParameters();
List<Size> sizes = p.getSupportedPictureSizes();
List<Size> previews = p.getSupportedPreviewSizes();
Size preview = previews.get(3);
// the size of preview is 7 and looped each item....
p.setPreviewSize(preview.width,preview.height);
int f=p.getJpegQuality();
Size size = sizes.get(3);
p.setJpegQuality(f);
p.setPictureSize(size.width,size.height);
mCamera.setParameters(p);
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mCamera.startPreview();
mPreviewRunning = true;
}
Anyone any idea?
Upvotes: 3
Views: 4975
Reputation: 4245
You need to maintain your aspect ratio.
Try setting your preview size to 640x480 if your device supports it. This will maintain an aspect ratio of 4:3.
If your dev doesn't support 640x480 try setting it to a different resolution which maintains an aspect ratio of 4:3.
You can set the preview size on the camera like this -
mCameraDevPara.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCameraDev.setParameters(mCameraDevPara);
Only after you set the preview size you can call the API mCameraDev.setPreviewDisplay(mSurfaceHolder);
and mCameraDev.startPreview();
Upvotes: 0
Reputation: 54725
Take a look at the PreviewFrameLayout class from the default Camera app. It's used to display SurfaceView
using the aspect ratio it must have.
Upvotes: 1