Why does a blurry image appear in a simple android camera app?

前端 未结 1 1120
渐次进展
渐次进展 2020-12-20 02:02

I tried to make a simple camera app that captures an image and views the image in an imageview: I tried this code in MainActivity:

 ImageView myImageView;

p         


        
相关标签:
1条回答
  • 2020-12-20 02:43

    I noticed that the captured image is very small in resolution!

    That is what your code asks for. Quoting the documentation for ACTION_IMAGE_CAPTURE:

    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.

    If you want a full-resolution image, use EXTRA_OUTPUT to indicate a file on external storage where you want the camera app to write the full-resolution image:

    package com.commonsware.android.camcon;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import java.io.File;
    
    public class CameraContentDemoActivity extends Activity {
      private static final int CONTENT_REQUEST=1337;
      private File output=null;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File dir=
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    
        output=new File(dir, "CameraContentDemo.jpeg");
        i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));
    
        startActivityForResult(i, CONTENT_REQUEST);
      }
    
      @Override
      protected void onActivityResult(int requestCode, int resultCode,
                                      Intent data) {
        if (requestCode == CONTENT_REQUEST) {
          if (resultCode == RESULT_OK) {
            Intent i=new Intent(Intent.ACTION_VIEW);
    
            i.setDataAndType(Uri.fromFile(output), "image/jpeg");
            startActivity(i);
            finish();
          }
        }
      }
    }
    

    (from this sample project)

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