mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Mise en place de la camera qui change en fonction de l'orientation + une image par dessus.
This commit is contained in:
+2
-1
@@ -24,7 +24,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CameraView"
|
||||
android:label="@string/title_activity_camera_view" >
|
||||
android:label="@string/title_activity_camera_view"
|
||||
android:screenOrientation="fullSensor">
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -7,16 +7,23 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/camera_preview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
android:layout_height="fill_parent">
|
||||
</FrameLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_capture"
|
||||
android:text="Capture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:alpha="0.5"
|
||||
android:contentDescription="@string/sss"
|
||||
android:src="@drawable/labs" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_capture"
|
||||
android:text="@string/capture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -6,5 +6,8 @@
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="title_activity_camera_view">CameraView</string>
|
||||
<string name="start_custom_camera">Start Custom Camera</string>
|
||||
<string name="capture">Capture</string>
|
||||
<string name="todo">TODO</string>
|
||||
<string name="sss">sss</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1,39 +1,62 @@
|
||||
package org.geneanet.testcustomcamera;
|
||||
|
||||
import org.geneanet.testcustomcamera.utils.CameraPreview;
|
||||
import org.geneanet.testcustomcamera.utils.CustomCamera;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.view.Display;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
|
||||
public class CameraView extends Activity {
|
||||
|
||||
private Camera mCamera;
|
||||
private CameraPreview mPreview;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//Remove title bar
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
//Remove notification bar
|
||||
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
setContentView(R.layout.activity_camera_view);
|
||||
|
||||
Camera cameraTest = CustomCamera.getCameraInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.camera_view, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
// Récupère les infos sur le device.
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
|
||||
// récupère l'objet gérant la camera puis l'oriente en fonction de l'écran.
|
||||
mCamera = CustomCamera.getCameraInstance();
|
||||
switch (display.getRotation()) {
|
||||
case CustomCamera.LANDSCAPE:
|
||||
mCamera.setDisplayOrientation(0);
|
||||
break;
|
||||
case CustomCamera.PORTRAIT:
|
||||
mCamera.setDisplayOrientation(90);
|
||||
break;
|
||||
case CustomCamera.LANDSCAPE_INVERSED:
|
||||
mCamera.setDisplayOrientation(180);
|
||||
break;
|
||||
case CustomCamera.PORTRAIT_INVERSED:
|
||||
mCamera.setDisplayOrientation(270);
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
// On assigne le rendu à la vue.
|
||||
mPreview = new CameraPreview(this, mCamera);
|
||||
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
|
||||
preview.addView(mPreview);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,22 @@ package org.geneanet.testcustomcamera.utils;
|
||||
import android.hardware.Camera;
|
||||
|
||||
public class CustomCamera {
|
||||
|
||||
protected static Camera mCamera = null;
|
||||
|
||||
// constantes sur les orientations de téléphones.
|
||||
public final static int PORTRAIT = 0;
|
||||
public final static int LANDSCAPE = 1;
|
||||
public final static int PORTRAIT_INVERSED = 2;
|
||||
public final static int LANDSCAPE_INVERSED = 3;
|
||||
|
||||
/** A safe way to get an instance of the Camera object. */
|
||||
public static Camera getCameraInstance(){
|
||||
// si on a déjà une camera récupérée dans l'application, on la retourne directement.
|
||||
if (CustomCamera.mCamera != null) {
|
||||
return mCamera;
|
||||
}
|
||||
// si non, on va chercher la camera de derrière.
|
||||
Camera c = null;
|
||||
try {
|
||||
c = Camera.open(0); // attempt to get a Camera instance
|
||||
@@ -14,6 +28,9 @@ public class CustomCamera {
|
||||
// Camera is not available (in use or does not exist)
|
||||
System.err.println("rt"+e);
|
||||
}
|
||||
|
||||
CustomCamera.mCamera = c;
|
||||
|
||||
return c; // returns null if camera is unavailable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user