Что и где я должен внедрить в код, чтобы искаженное изображение не появлялось для пользовательского проекта камеры в AndroidStudio? - PullRequest
0 голосов
/ 08 марта 2020

** Я использую Mi A1 и создаю собственный проект камеры в android. Отображаемый результат искажен **

Необходимо выяснить, как решить эту проблему, в самом коде ниже. Новое в android, поэтому было бы полезно подробное описание.

package com.example.camera;
import...

public class MainActivity extends AppCompatActivity {

    //Defining the pic id
    private static final int pic_id= 123;

    //Defining the button, ImageView and setting camera picture size
    Button camera_open_id;
    ImageView click_image_id;

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


        // By ID we can get each component
        // which id is assigned in XML file
        // get Buttons and imageview.

        camera_open_id=(Button)findViewById(R.id.camera_button);
        click_image_id=(ImageView)findViewById(R.id.click_image);

        // Camera_open button is for open the camera
        // and add the setOnClickListener in this button
        camera_open_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // Create the camera_intent ACTION_IMAGE_CAPTURE
                // it will open the camera for capture the image
                Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                // Start the activity with camera_intent,
                // and request pic id

                startActivityForResult(camera_intent,pic_id);
            }

        });
    }

    // This method will help to retrieve the image
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

        // Match the request 'pic id with requestCode
        if (requestCode == pic_id) {
            // BitMap is data structure of image file
            // which stores the image in memory

            Bitmap photo = (Bitmap)data.getExtras().get("data");
            // Set the image in imageview for display
            click_image_id.setImageBitmap(photo);
        }}
}
...