简体   繁体   English

如何提高位图质量?

[英]How to increase Bitmap quality?

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);
    }
  }
}  

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. 当您返回onActivityResult时,图像将存储到您定义的路径中。 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. 此功能将返回最后捕获的图​​像路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM