0

enter image description here

I've been looking for information on Google for 2 days. But all without results.

I want to use not the full screen mode, but the reduced one, so that you can scan a certain area.

In Api Google, I also did not find what I needed.

The variant with resizing in SurfaceView is attached with a picture.

As you can see, the result is deplorable ((.

Is there a solution to my problem?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">

<SurfaceView
    android:layout_centerInParent="true"
    android:id="@+id/surface_view"
    android:layout_width="match_parent"
    android:layout_height="100dp"/>

<TextView
    android:id="@+id/txtView"
    android:text="No Text"
    android:layout_alignParentBottom="true"
    android:textColor="@android:color/white"
    android:textSize="20sp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
 </RelativeLayout>

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.surface_view) SurfaceView cameraView;
    @BindView(R.id.txtView) TextView txtView;

    CameraSource cameraSource;
    final int RequestCameraPermissionID = 1001;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode){
            case RequestCameraPermissionID:
                if (grantResults[0]==PackageManager.PERMISSION_GRANTED){
                    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                            return;
                    }
                    try {
                        cameraSource.start(cameraView.getHolder());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
        if (!textRecognizer.isOperational()) {
            Log.e("MainActivity", "onCreate= " + "Detecter");
        } else {

            cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer )
                    .setFacing(CameraSource.CAMERA_FACING_BACK)
                    .setRequestedFps(2.0f)
                    .setAutoFocusEnabled(true)
                    .build();

            cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    try {
                        if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                            ActivityCompat.requestPermissions(MainActivity.this,
                                    new String[]{Manifest.permission.CAMERA},
                                    RequestCameraPermissionID);
                            return;
                        }
                        cameraSource.start(cameraView.getHolder());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

                }

                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                    cameraSource.stop();
                }
            });

            textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
                @Override
                public void release() {

                }

                @Override
                public void receiveDetections(Detector.Detections<TextBlock> detections) {
                    final SparseArray<TextBlock> items=detections.getDetectedItems();
                    if (items.size()!=0){
                        txtView.post(() -> {
                           StringBuilder stringBuilder=new StringBuilder();
                            for (int i = 0; i < items.size(); i++) {
                                TextBlock item=items.valueAt(i);
                                stringBuilder.append(item.getValue());
                                stringBuilder.append("\n");
                            }
                            txtView.setText(stringBuilder.toString());
                        });
                    }
                }
            });
        }
    }
}
Prost
  • 169
  • 1
  • 7
  • 1
    Check this out: https://stackoverflow.com/questions/17348614/make-a-surfaceview-larger-than-the-screen-fitting-a-camera-preview-to-a-surface – Ashim Neupane Apr 13 '18 at 09:57
  • @AshimNeupane, Thank you, but for a beginner like me it's complicated. Can you know how to add an instance of CameraSource to the Camera class? That would solve a lot of problems. Since the class Advanced Camera – Prost Apr 13 '18 at 10:15

0 Answers0