Guest User

Untitled

a guest
Jan 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. this.surf = (SurfaceView) findViewById(R.id.surf);
  2. this.surf.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  3. this.surf.addCallback(new Callback() {
  4.  
  5. @Override
  6. public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
  7. Cam.this.h = holder;
  8. }
  9.  
  10. @Override
  11. public void surfaceCreated(SurfaceHolder holder) {
  12. Cam.this.h = holder;
  13. }
  14.  
  15. @Override
  16. public void surfaceDestroyed(SurfaceHolder holder) {
  17. }
  18.  
  19. });
  20.  
  21. MediaRecorder mMediaRecorder = new MediaRecorder();
  22. mMediaRecorder.setCamera(Cam.this.mCamera);
  23. mMediaRecorder.setAudioSource(AudioSource.MIC);
  24. mMediaRecorder.setVideoSource(VideoSource.CAMERA);
  25. mMediaRecorder.setPreviewDisplay(Cam.this.surf);
  26. mMediaRecorder.setOutputFormat(OutputFormat.MPEG_4);
  27. mMediaRecorder.setAudioEncoder(AudioEncoder.DEFAULT);
  28. mMediaRecorder.setVideoEncoder(VideoEncoder.H264);
  29. mMediaRecorder.setVideoSize(1280, 720);
  30. mMediaRecorder.setOutputFile(Cam.this.mParcelFileDescriptor[1].getFileDescriptor());
  31. mMediaRecorder.setMaxDuration(60000);
  32. mMediaRecorder.prepare();
  33. mMediaRecorder.start();
  34.  
  35. View v = findViewById(R.id.mainLayout); // основная компоновка (в моём случае RelativeLayout)
  36. v.setDrawingCacheEnabled(true);
  37. v.buildDrawingCache(true);
  38. Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
  39. v.setDrawingCacheEnabled(false);
  40. FileOutputStream o = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "frame.jpeg"));
  41. b.compress(CompressFormat.JPEG, 100, o);
  42. o.flush();
  43. o.close();
  44.  
  45. <RelativeLayout
  46. xmlns:android="http://schemas.android.com/apk/res/android"
  47. xmlns:tools="http://schemas.android.com/tools"
  48. android:id="@+id/mainLayout"
  49. android:layout_width="match_parent"
  50. android:layout_height="match_parent"
  51. tools:context="test.Cam" >
  52.  
  53. <SurfaceView
  54. android:id="@+id/surface"
  55. android:layout_width="match_parent"
  56. android:layout_height="match_parent" />
  57.  
  58. </RelativeLayout>
Add Comment
Please, Sign In to add comment