I created a layout where my surface view has been resized from the “original size”, I did the following:
ViewGroup.LayoutParams params = mSurfaceView.getLayoutParams();
int mPixels=getResources().getDimensionPixelSize(R.dimen.profile_pic_dimension); //200
params.width=mPixels;
params.height=mPixels;
mSurfaceView.setLayoutParams(params);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
and I obtain a view like this:
http://img412.imageshack.us/img412/9379/layoutp.png
but then.. whenever I take the picture.. it doesn’t saves as how I can see it on the view… but instead it saves it normal size like if the view was taking the whole screen (like if the surfaceview was never resized).
I tried using this:
Camera.ShutterCallback mShutterCallback = new Camera.ShutterCallback() {
@Override
public void onShutter() {
Camera.Parameters p = mCamera.getParameters();
p.setPictureSize(mSurfaceView.getWidth(), mSurfaceView.getHeight());
mCamera.setParameters(p);
}
};
but still didn’t get the image size i wanted to.
You cannot just supply any width and height value when setting the picture (or preview) size. In stead, you’ll have to use one of the items from the list of supported sizes, which you can retrieve by calling
getSupportedPictureSizes()(there’s an equivalent for the preview).So far I haven’t come across any devices that support taking square pictures, so after a 4:3, 16:9, 16:10, or whatever ratio, picture has been taken, you will have to ‘cut’ out the relevant part yourself, and optionally scale it down to a specific dimension. Probably the most straightforward way to do this, is by creating a new Bitmap as a subset from a source Bitmap (and then optionally scale it down). In order to get the source bitmap, you’ll likely need to hook up a
PictureCallbackto the camera withtakePicture(...).