Cómo tomar una foto (instantánea) mientras el video se ha grabado con la vista de la superficie

Estoy hecho con la grabación de vídeo con vista de la superficie. Ahora quiero saber "cómo tomar una foto (instantánea), mientras que el video se ha grabado con la vista de la superficie" ?? ¿Puede alguien ayudarme por favor.! ¿Qué necesito agregar en el botón mycam para tomar foto?

public class ActiveCam extends Activity implements SurfaceHolder.Callback { boolean recording = false; MediaRecorder mediaRecorder; SurfaceHolder surfaceHolder; Button myStart; Button myStop; Button mycam; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); recording = false; mediaRecorder = new MediaRecorder(); initMediaRecorder(); setContentView(R.layout.camact); //This is my XML file Button b3=(Button)findViewById(R.id.button3); SurfaceView myVideoView = (SurfaceView)findViewById(R.id.preview); surfaceHolder = myVideoView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); myStart = (Button)findViewById(R.id.button1); myStart.setOnClickListener(myButtonOnClickListener); myStop = (Button)findViewById(R.id.button2); myStop.setOnClickListener(myButtonOnClickListener1); mycam = (Button)findViewById(R.id.button3); mycam.setOnClickListener(myButtonOnClickListener3); } private Button.OnClickListener myButtonOnClickListener1 = new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mediaRecorder.stop(); mediaRecorder.release(); mediaRecorder = null; //finish(); } }; Camera.PictureCallback mCall = new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { //decode the data obtained by the camera into a Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); //set the iv_image Toast.makeText(ActiveCam.this,"cap", Toast.LENGTH_LONG).show(); //iv_image.setImageBitmap(bmp); } }; private Button.OnClickListener myButtonOnClickListener3 = new Button.OnClickListener() { @Override public void onClick(View arg0) { //I need to take picture after pressing this button...What I needs to add here??? } }; private Button.OnClickListener myButtonOnClickListener = new Button.OnClickListener() { @Override public void onClick(View arg0) { mediaRecorder.start(); recording = true; myStop.setText("STOP"); } }; @Override public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void surfaceCreated(SurfaceHolder arg0) { // TODO Auto-generated method stub prepareMediaRecorder(); } @Override public void surfaceDestroyed(SurfaceHolder arg0) { // TODO Auto-generated method stub } private void initMediaRecorder() { mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mediaRecorder.setProfile(camcorderProfile_HQ); mediaRecorder.setOutputFile("/sdcard/your.mp4"); //mediaRecorder.setMaxFileSize(..set size..); } private void prepareMediaRecorder() { mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface()); try { mediaRecorder.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

Este es mi archivo XML

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Start" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="16dp" android:text="Pause" /> <SurfaceView android:id="@+id/preview" android:layout_width="500px" android:layout_height="500px" android:layout_alignLeft="@+id/textView1" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="34dp" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/spinner1" android:layout_marginLeft="20dp" android:layout_marginTop="36dp" android:text="Button" /> </RelativeLayout> 

RecordingView link & link. Usted puede tomar la instantánea por este código Si usted tiene un videoView en su xml que usted tiene que hacer linearLayout como su padre (videoView como hijo de linearLayout) y cuando usted ahorrará linearlayout imagen que significa que va a guardar su Imagen de videovista.

Pruebe esto y lea el código que he enviado para tomar la instantánea.

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Start" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="16dp" android:text="Pause" /> <ImageView android:layout_width="120dip" android:layout_height="120dip" android:text="Take Screenshot" android:id="@+id/ImageView01" android:layout_centerHorizontal="true" /> <LinearLayout android:orientation="vertical" android:layout_width="500px" android:layout_height="500px" android:id="@+id/LinearLayout01" android:layout_alignLeft="@+id/textView1" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="#FF0000" android:layout_marginBottom="34dp"> <SurfaceView android:id="@+id/preview" android:layout_width="400px" android:layout_height="400px" android:layout_gravity="center" /> </LinearLayout> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/spinner1" android:layout_marginLeft="20dp" android:layout_marginTop="36dp" android:text="Button" /> </RelativeLayout> 

Espero que ayude

Agregue esto en Button3 Listner

 private Button.OnClickListener myButtonOnClickListener3 = new Button.OnClickListener() { @Override public void onClick(View arg0) { //I need to take picture after pressing this button...What I needs to add here??? //View v1 = L1.getFocusedChild(); L1.setDrawingCacheEnabled(true); Bitmap bm = L1.getDrawingCache(); BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); ImageView image = (ImageView) findViewById(R.id.ImageView01); image.setBackgroundDrawable(bitmapDrawable); } }; 

Cambie su gestor de superficie

 <SurfaceView android:id="@+id/preview" android:layout_width="400px" android:layout_height="400px" android:layout_gravity="center" /> 

Y agregue android:background="#FF0000" en su diseño lineal

Que le ayudará a averiguar que hace ur código de instantánea funciona o no

  • SurfaceHolder.lockCanvas () toma demasiado tiempo para mi aplicación de juego
  • SuperficieCreada () Nunca llamado
  • Crear ImageView de forma programática sin diseño
  • Cómo escalar el video en un SurfaceView más grande que la ventana en Android?
  • Imagen de leva en el soporte de superficie, dibujar: Excepción debido al tipo de superficie
  • agregar imagen a la vista de la superficie en android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.