How to take a snapshot (snapshot) while the video was recorded using a surface image

I recorded a video with a view of the surface. Now I want to know how to take a snapshot (snapshot) while the video was recorded using a superficial view "?? Can anyone help me.! What needs to be added to the mycam button to take a snapshot?

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(); } } 

This is my xml file

 <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> 
+4
source share
1 answer

RecordingView and link . You can take a snapshot with this code If you have video in your xml, you must make linearLayout your parent (videoView as a child of linearLayout), and when you save the linearlayout image, it means that you will save your video image.

Try this and read this code that I sent to take the picture.

  <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> 

Hope this helps

Add this to 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); } }; 

Change your surface manager and height

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

and add android:background="#FF0000" to your line layout

this will help you understand if ur snapshot code is working or not

+1
source

All Articles