0

My activity layout is this :-

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RecordVideo">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/camview"
    android:layout_height="fill_parent">

    <FrameLayout
        android:id="@+id/camera_preview"
        android:adjustViewBounds="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <SurfaceView
        android:id="@+id/sview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <ImageView
        android:id="@+id/ImgLogo1"
        android:layout_width="80dp"
        android:src="@drawable/rotating_earth"
        android:layout_alignParentLeft="true"
        android:layout_height="80dp" />

    <ImageView
        android:id="@+id/ImgLogo2"
        android:layout_width="80dp"
        android:src="@mipmap/ic_launcher"
        android:layout_alignParentRight="true"
        android:layout_height="80dp" />

    <ImageButton
        android:id="@+id/button_capture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="?android:attr/selectableItemBackground"
        android:src="@mipmap/img_record_green"
        android:layout_gravity="center" />

</RelativeLayout>

I am taking screen shot during video capture and setting jpeg image in framelayout like this :-

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap bMap = BitmapFactory.decodeFile(tmpFile.toString(), options);
Bitmap BbMap = Bitmap.createScaledBitmap(bMap, size.x, size.y,true);

preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.setBackground(new BitmapDrawable(BbMap));

Code is capturing screen shot, but it leaves the vertical space of ImgLogo1 (right) and ImgLogo2 (left) as black. I want to capture screen shot from camera as full screen along with ImgLogo1 and ImgLogo2 as well in the screen shot. Can anybody tell how to achieve this..

First screen shot is this : enter image description here

Second screen shot is this :- enter image description here

First screen shot should be as wide as second one, but These 2 imageview's don't let it expand.

Dev
  • 260
  • 4
  • 18
  • 34

1 Answers1

1

This will help capturing the screenshot of your whole screen

   try {
                getWindow().getDecorView().findViewById(android.R.id.content).setDrawingCacheEnabled(true);
                Bitmap backBitmap = getWindow().getDecorView().findViewById(android.R.id.content).getDrawingCache();
                Bitmap bmOverlay = Bitmap.createBitmap(
                        backBitmap.getWidth(), backBitmap.getHeight(),
                        backBitmap.getConfig());
                Canvas canvas = new Canvas(bmOverlay);
                canvas.drawBitmap(backBitmap, 0, 0, null);
                try {
                    FileOutputStream fos = new FileOutputStream(new File(Environment
                            .getExternalStorageDirectory().toString(), "SCREEN"
                            + System.currentTimeMillis() + ".png"));


                    // Write the string to the file
                    bmOverlay.compress(Bitmap.CompressFormat.JPEG, 90, fos);
                    fos.flush();
                    fos.close();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    Log.d("ImageCapture", "FileNotFoundException");
                    Log.d("ImageCapture", e.getMessage());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    Log.d("ImageCapture", "IOException");
                    Log.d("ImageCapture", e.getMessage());
                }


            } catch (Exception e) {
                e.printStackTrace();
            }
Brijesh Joshi
  • 1,817
  • 1
  • 9
  • 24
  • can you share the snapshot – Brijesh Joshi Jul 17 '18 at 11:51
  • I am making an app that captures screen shots during video and whatever activity is done on the screen by user is captured as screen shots and afterwards all these images will combine to form a movie with FFMpeg. That is the IDEA.. – Dev Jul 17 '18 at 12:07
  • Okay. But it will be helpful if you share the screen shot you are getting to identify the problem – Brijesh Joshi Jul 17 '18 at 12:08
  • I have added the screen shots – Dev Jul 17 '18 at 12:09
  • The black portion which you are getting is might be of the `surfaceView` that you used. Please follow [this answer](https://stackoverflow.com/a/27824250/9734616) to check that out. – Brijesh Joshi Jul 17 '18 at 12:15