bitmap bad quality after set to imageview

后端 未结 2 1738
遥遥无期
遥遥无期 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 :)

    0 讨论(0)
  • 2020-12-22 12:41

    Use something other than the thumbnail. Quoting the documentation for ACTION_IMAGE_CAPTURE, with emphasis added:

    The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

    So, specify a Uri in EXTRA_OUTPUT where a full camera image should be written to. Then, use an image-loading library, like Picasso, to load the photo into your ImageView.

    Here is a sample app that demonstrates using EXTRA_OUTPUT.

    0 讨论(0)
提交回复
热议问题