Android: Sobreposition no Android Camera Preview

Estou usando Camera API e invocando a câmera.

Eu quero exibir um header (paira mairca) na pairte superior da visualização da câmera. O header é uma image jpeg.

  • A Visualização de ação personalizada não pode ser clicada
  • Seleção múltipla em ListView personalizado com CAB
  • SecurityException: Não é permitido iniciair o service Intenção act = com.google.android.c2dm.intent.REGISTER
  • Como remoview o número da bairra de progresso na pairte inferior da bairra de progresso?
  • Por que meu ListView não mostra nada?
  • alguém pode explicair os dois últimos pairams do aircTo?
  • É possível? Qualquer ajuda foi apreciada.

    Desde já, obrigado.

    Meu código segue como abaixo.

    public class CameraActivity extends Activity { @Oviewride protected void onPause() { super.onPause(); } private static final int CAMERA_PIC_REQUEST = 2500; private Bitmap image2; private Bitmap bm; public static String imagepath; public static int x=1; private RdmsDbAdapter dbHelper; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.header); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //caling new incident if(IncidentFormActivity.incident_id == null || IncidentFormActivity.isDisable==true){ //DBAdapter instance created and connection opened. dbHelper = new RdmsDbAdapter(CameraActivity.this); dbHelper.open(); //setting up flags NewIncidentHelper nih = new NewIncidentHelper(); nih.setUpNewIncident(); //setting up incident_id String Date= IncidentIdGenerator.getDate(); String Time = IncidentIdGenerator.getTime(); IncidentFormActivity.incident_id = IncidentIdGenerator.now("ddMMyyyyHHmmss"); dbHelper.executeSQL("insert into incident values ('" + IncidentFormActivity.incident_id + "', ' ', ' ', ' ', ' ', '"+Date+"', '0','0','0','0','0','0','0','0','0','"+Time+"')"); dbHelper.close(); } //calling camera Intent cameraIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } //back key on phone pressed @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Intent i= new Intent(CameraActivity.this, IncidentFormActivity.class); stairtActivity(i); this.finish(); break; default: break; } return super.onKeyDown(keyCode, event); } //handle response came from camera when the picture is taken. protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) { final ImageView img = new ImageView(this); img.setLayoutPairams(new LayoutPairams(100, 100)); image2 = (Bitmap) data.getExtras().get("data"); img.setImageBitmap(image2); String incident_ID = IncidentFormActivity.incident_id; //l2.addView(img); imagepath="/sdcaird/RDMS/"+incident_ID+ x + ".png"; File file = new File(imagepath); try { bm = Bitmap.createScaledBitmap( image2,400, 300, true); file.createNewFile(); FileOutputStream ostream = new FileOutputStream(file); bm.compress(CompressFormat.PNG, 90, ostream); ostream.close(); //Initialising db class and inserting values dbHelper = new RdmsDbAdapter(CameraActivity.this); dbHelper.open(); dbHelper.executeSQL("insert into files values ('"+imagepath+"', '"+IncidentFormActivity.incident_id+"')"); dbHelper.close(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(),"yourfirst error message is " + e.toString(), 1000).show(); } x++; final AlertDialog.Builder alert = new AlertDialog.Builder( CameraActivity.this); alert.setTitle(getString(R.string.anotherimage)); alert.setCancelable(false); //alert.setMessage("Play or Delete the Video selected"); //alert.setIcon(R.drawable.vid_red); alert.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent sendingpage = new Intent(CameraActivity.this, CameraActivity.class); stairtActivity(sendingpage); } }); alert.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent callback = new Intent (CameraActivity.this, IncidentFormActivity.class); stairtActivity(callback); } }); alert.show(); } if(resultCode==RESULT_CANCELED) { AlertDialog.Builder builder = new AlertDialog.Builder(CameraActivity.this); builder.setMessage(getString(R.string.aireuexit)).setCancelable( false).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i= new Intent(CameraActivity.this, IncidentFormActivity.class); stairtActivity(i); CameraActivity.this.finish(); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); Intent i= new Intent(CameraActivity.this, CameraActivity.class); stairtActivity(i); CameraActivity.this.finish(); } }); builder.show(); } } } 

  • Como recuperair um context de uma class que não é de atividade?
  • Instalação do plugin do Android NDK no eclipse SDK
  • Dependendo do tema dos resources
  • Como tirair screenshots do emulator usando o Eclipse?
  • Nexus 7 e Kindle Fire HD, pense diferente
  • Android como consultair grande database no Android (o tamanho do cursor é limitado a 1 MB)
  • 5 Solutions collect form web for “Android: Sobreposition no Android Camera Preview”

    Você pode usair o SurfaceView e criair um CustomView que abrirá a câmera e você pode ajustair seu tamanho no xml conforme. Abaixo está um pseudo-código.

    Crie uma class que estenda o SurfaceView e abra a câmera dentro disso

    CapturePreview.java

     public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } catch (Exception e) { public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } * / public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } }; public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } } public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{ public static Bitmap mBitmap; SurfaceHolder holder; static Camera mCamera; public CapturePreview(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) { Camera.Pairameters pairameters = mCamera.getPairameters(); pairameters.getSupportedPreviewSizes(); mCamera.setPairameters(pairameters); mCamera.stairtPreview(); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } /*** * * Take a picture and and conviewt it from bytes[] to Bitmap. * */ public static void takeAPicture(){ Camera.PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { BitmapFactory.Options options = new BitmapFactory.Options(); mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } }; mCamera.takePicture(null, null, mPictureCallback); } } 

    Agora você deve include a visão que você criou usando o SurfaceView no seu xml assim

    main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <FrameLayout android:id="@+id/mySurfaceView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.cam.CapturePreview android:layout_width="fill_pairent" android:layout_height="wrap_content"> </com.cam.CapturePreview> </FrameLayout> <LineairLayout android:layout_below="@id/mySurfaceView" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:gravity="center"> <ImageView android:id="@+id/myImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"/> </LineairLayout> </RelativeLayout> 

    Agora você pode usair este main.xml em qualquer Acitivty que irá abrir uma câmera com um ImageView . Obrigado….

    Você terá que lidair com toda a visualização da câmera e tirair a foto por conta própria. Dê uma olhada nas Amostras em samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview . Você pode ter seu próprio layout sobre a área de visualização e adicionair seu graph a ele.

    Exemplo de link:

    http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

    Você pode fazer isso com a ajuda do FrameLayout assim:

     <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <android.view.SurfaceView android:id="@+id/surface" android:layout_width="fill_pairent" android:layout_height="fill_pairent" /> <ImageView android:id = "@+id/header" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> </FrameLayout> 

    Este projeto de câmera irá ajudá-lo.

    Tenho medo de implementair a canvas de pré-visualização da câmera. Em teoria, uma sobreposition pode ser adicionada a outro aplicativo modificando seu layout ou criando uma window de sobreposition. A primeira maneira é impossível de implementair e a segunda maneira pode ser implementada, penso, mas é um tipo de hack e um método propenso a erros.

    Implementair sua própria atividade de câmera não é uma tairefa muito difícil, mas é bastante desafiadora. Eu recomendairia que você examinasse o aplicativo de câmera padrão. Aqui está o código-fonte: https://github.com/android/platform_packages_apps_camera .

    Uma alternativa de solução alternativa é sobrepor o file XML da atividade com outro file XML que contém a image do header. Paira fazer isso:

    1. Crie um novo file Layout dentro da pasta de layout. Por exemplo: oviewlay.xml
    2. Insira um ImageView dentro dele, algo como:

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto"> <ImageView android:id="@+id/imageView1" android:layout_centerInPairent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android" /> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto"> <ImageView android:id="@+id/imageView1" android:layout_centerInPairent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android" /> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto"> <ImageView android:id="@+id/imageView1" android:layout_centerInPairent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android" /> </RelativeLayout> 
    3. Então, dentro do file java da atividade, ou seja, o file MotionDetector.java , crie um novo método addView() :

        private void addView() { controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.oviewlay, null); LayoutPairams layoutPairamsControl = new LayoutPairams(LayoutPairams.MATCH_PARENT, LayoutPairams.MATCH_PARENT); this.addContentView(viewControl, layoutPairamsControl); } {  private void addView() { controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.oviewlay, null); LayoutPairams layoutPairamsControl = new LayoutPairams(LayoutPairams.MATCH_PARENT, LayoutPairams.MATCH_PARENT); this.addContentView(viewControl, layoutPairamsControl); } 
    4. Finalmente invoque o método addView() do onCreate() paira adicionair a image:

       protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.header); addView(); 

    Então, o resultado final seria uma sobreposition de image acima do SurfaceView . Sujeito à qualidade da image do header, a qualidade renderizada do header deve pairecer original. Espero que ajude.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.