9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2026-05-02 00:07:24 +08:00

Premier jet de la photo taille optimale (marche sur tablette mais pas sur telephone

This commit is contained in:
Thomas BOY
2015-01-16 15:45:47 +01:00
parent 70e8b89d48
commit 3e98f21c2e
3 changed files with 38 additions and 6 deletions
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/globalLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
android:layout_height="1067dp"
android:gravity="center" >
</FrameLayout>
<ImageView
@@ -198,10 +198,42 @@ public class CameraActivity extends Activity {
customCamera.setDisplayOrientation(orientation);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
final int widthScreen = dm.widthPixels;
final int heightScreen = dm.heightPixels;
FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);
LayoutParams paramsCameraPreview =
(LayoutParams) cameraPreview.getLayoutParams();
Size camParameters = customCamera.getParameters().getPictureSize();
int minSize;
int maxSize;
if (camParameters.width > camParameters.height) {
maxSize = camParameters.width;
minSize = camParameters.height;
} else {
maxSize = camParameters.height;
minSize = camParameters.width;
}
float ratio;
if (widthScreen > heightScreen) {
paramsCameraPreview.height = LayoutParams.FILL_PARENT;
ratio = ( (float)minSize / (float)heightScreen );
paramsCameraPreview.width = (int)(maxSize / ratio);
} else {
paramsCameraPreview.width = LayoutParams.FILL_PARENT;
ratio = ( (float)minSize / (float)widthScreen );
paramsCameraPreview.height = (int)(maxSize / ratio);
}
cameraPreview.setLayoutParams(paramsCameraPreview);
// Assign the render camera to the view
CameraPreview myPreview = new CameraPreview(this, customCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(myPreview);
cameraPreview.addView(myPreview);
// The zoom bar progress
final SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel);
@@ -38,7 +38,7 @@ public class ManagerCamera {
return cam; // returns null if camera is unavailable
}
/**
* To release the camera.
*/