bitmap bad quality after set to imageview

后端 未结 2 1740
遥遥无期
遥遥无期 2020-12-22 12:26

I am creating a app that opens camera for user and after image captured it will be shows on ImageView! But the image in ImageView has very bad quality
here is the code:

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 12:39

    This is how I made it work for me! Assuming you are capturing an image, and would like to show the captured image in a new Activity, you can follow this way:

    First on the click of button you can:

     public void cameraFuture(View view) // <-- onClick() method of Camera Button
    {
        Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory(),
                "MyPhoto.jpg");
        outPutfileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outPutfileUri);
        startActivityForResult(intent, TAKE_PIC);
    }
    

    Then on the onActivityResult() method, you can do this way:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == TAKE_PIC && resultCode==RESULT_OK){
            Toast.makeText(this, outPutfileUri.toString(),Toast.LENGTH_LONG).show();
    
            Intent bitIntent = new Intent(this, CameraTake.class);
            bitIntent.putExtra("imageUri", outPutfileUri);
            startActivity(bitIntent);
            finish();
    
    
        }
    
    }
    

    And in the next Activity, you can receive the file this way:

    Intent receiveIntent = getIntent();
    
        uri = receiveIntent.getParcelableExtra("imageUri");
    
    
        if (savedInstanceState == null) {
            Bundle extras = getIntent().getExtras();
            if(extras == null) {
                receiveImg= null;
            } else {
                receiveImg= extras.getString("PASSER");
            }
        } else {
            receiveImg= (String) savedInstanceState.getSerializable("PASSER");
        }
    
    
    
    
        File imgFile = new  File(Environment.getExternalStorageDirectory(),"MyPhoto.jpg");
    
        if(imgFile.exists()){
    
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    
            ImageView myImage = (ImageView) findViewById(R.id.camOut);
    
            myImage.setImageBitmap(myBitmap);
    
        }
    

    Hope it helps! Happy coding :)

提交回复
热议问题