How to increase Bitmap quality?

好久不见. 提交于 2020-01-03 02:43:07

问题


In the app I'm working on, a button opens the camera. When you take a picture, that picture is loaded into the app as a Bitmap. The pictures are very pixelated. How can I increase the quality of the bitmap after it has been loaded into my app?

Code so far:

private static final int CAMERA_PIC_REQUEST = 2500;




@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    Button capture = (Button) findViewById(R.id.captureButton);
    Button flip = (Button) findViewById(R.id.flipButton);
    final TextView text = (TextView) findViewById(R.id.text);


    capture.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            text.setVisibility(View.GONE);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
        }
    }); 


    flip.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {




        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == CAMERA_PIC_REQUEST){
        Bitmap image = (Bitmap) data.getExtras().get("data");
        ImageView imageView = (ImageView) findViewById(R.id.ImageView01);
        imageView.setImageBitmap(image);
    }
  }
}  

回答1:


Do not get that image from data, it is always a low quality image. Try using a file path and get the image from file path.

Open Camera

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(path));
startActivityForResult(intent, CAMERA_PIC_REQUEST);

And when you return to onActivityResult the image will be stored to your defined path. You can get the high resolution image from there. Or you can also use a function to get last captured image ...

    private String getLastImagePath() {
        final String[] imageColumns = { MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DATA };
        final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
        Cursor imageCursor = managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
                null, null, imageOrderBy);
        if (imageCursor.moveToFirst()) {
            int id = imageCursor.getInt(imageCursor
                    .getColumnIndex(MediaStore.Images.Media._ID));
            String fullPath = imageCursor.getString(imageCursor
                    .getColumnIndex(MediaStore.Images.Media.DATA));
            return fullPath;
        } else {
            return "";
        }
    }

This function will return you the last captured image path.



来源:https://stackoverflow.com/questions/10958626/how-to-increase-bitmap-quality

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!