Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.surf = (SurfaceView) findViewById(R.id.surf);
- this.surf.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- this.surf.addCallback(new Callback() {
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- Cam.this.h = holder;
- }
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- Cam.this.h = holder;
- }
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- }
- });
- MediaRecorder mMediaRecorder = new MediaRecorder();
- mMediaRecorder.setCamera(Cam.this.mCamera);
- mMediaRecorder.setAudioSource(AudioSource.MIC);
- mMediaRecorder.setVideoSource(VideoSource.CAMERA);
- mMediaRecorder.setPreviewDisplay(Cam.this.surf);
- mMediaRecorder.setOutputFormat(OutputFormat.MPEG_4);
- mMediaRecorder.setAudioEncoder(AudioEncoder.DEFAULT);
- mMediaRecorder.setVideoEncoder(VideoEncoder.H264);
- mMediaRecorder.setVideoSize(1280, 720);
- mMediaRecorder.setOutputFile(Cam.this.mParcelFileDescriptor[1].getFileDescriptor());
- mMediaRecorder.setMaxDuration(60000);
- mMediaRecorder.prepare();
- mMediaRecorder.start();
- View v = findViewById(R.id.mainLayout); // основная компоновка (в моём случае RelativeLayout)
- v.setDrawingCacheEnabled(true);
- v.buildDrawingCache(true);
- Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
- v.setDrawingCacheEnabled(false);
- FileOutputStream o = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "frame.jpeg"));
- b.compress(CompressFormat.JPEG, 100, o);
- o.flush();
- o.close();
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/mainLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="test.Cam" >
- <SurfaceView
- android:id="@+id/surface"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </RelativeLayout>
Add Comment
Please, Sign In to add comment