Dev
Dev

Reputation: 360

Taking screen shot from camera dosen't show full screen android

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.

Upvotes: 0

Views: 98

Answers (1)

Brijesh Joshi
Brijesh Joshi

Reputation: 1857

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

Upvotes: 1

Related Questions