相机解析度

时间:2018-10-18 13:41:04

标签: android json codeigniter camera resolution

当我使用android版本6和以前的版本拍照时,图片分辨率没有问题,但是当我使用android版本7和之前的版本拍照时 使用相机意图拍摄后最新的图像,图像质量的像素变低。 我该如何解决这个问题?

这是我的代码:

    private void cameraIntent() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, REQUEST_CAMERA);
    }  

     @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
//        Log.i("convTech", "onActivityResult");
//        Log.i("convTech", "requestCode:: "+requestCode);
//        Log.i("convTech", "resultCode:: "+resultCode);
//        Log.i("convTech", "data:: "+data.getData());


        if (requestCode == SELECT_FILE && resultCode == Activity.RESULT_OK ) {
//            if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
            try {

                btnTakeCapture.setVisibility(View.GONE);
                btnRetake.setVisibility(View.VISIBLE);
                btnComfirmImage.setVisibility(View.VISIBLE);
                notClear.setVisibility(View.VISIBLE);

                onCaptureImageResult(data);

                Log.i("convTech", "Data is Image");
//                Uri selectedImage = data.getData();
                Uri selectedImage = Uri.fromFile(destination);

//                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                ivImage.setImageBitmap(bitmap);


//                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
//                cursor.moveToFirst();

//                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//                file_path = cursor.getString(columnIndex);
                file_path= selectedImage.getPath().toString();
                Log.d("ConvTech::", "file_path:: " + file_path);
//                cursor.close();
//                cursor.close();


            } catch (CursorIndexOutOfBoundsException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

     private void onCaptureImageResult(Intent data) {
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);

        root = new File(Environment.getExternalStorageDirectory()+ File.separator + "JoPost" + File.separator);
        root.mkdirs();
        destination = new File(root, System.currentTimeMillis() + ".jpg");
        Log.d("ConvTech", "destination Path:: "+destination.getPath());


        try {
            destination.createNewFile();
            fo = new FileOutputStream(destination);
            thumbnail.compress(Bitmap.CompressFormat.PNG, 100, fo);
            fo.flush();
            fo.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        ivImage.setImageBitmap(thumbnail);
    }

0 个答案:

没有答案