通过从相机拍照来裁剪图像

时间:2016-08-04 11:28:02

标签: android

 imageBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                reset();
              Intent intent = new Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");
            startActivityForResult(intent, REQUEST_PICK);

            }
        });

    doneBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final ProgressDialog dialog = ProgressDialog.show(StudentDetails.this, null, "Please wait…", true, false);
                cropView.setVisibility(View.GONE);
                layout4.setVisibility(View.GONE);
                resultIv.setVisibility(View.VISIBLE);
                layout3.setVisibility(View.GONE);
                layoutUpload.setVisibility(View.VISIBLE);
                //       editTextName.setVisibility(View.GONE);
                buttonUpload.setVisibility(View.VISIBLE);

                new Thread() {
                    public void run() {
                        croppedBitmap = cropView.getOutput();

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                // cropped image set
                                resultIv.setImageBitmap(croppedBitmap);
                            }
                        });

                        Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
                        CropUtil.saveOutput(StudentDetails.this, destination, croppedBitmap, 1);

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                dialog.dismiss();
                            }
                        });
                    }
                }.start();
            }
        });

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

        if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) {
            filePath = data.getData();        
            cropView.setVisibility(View.VISIBLE);
            layoutImage.setVisibility(View.VISIBLE);
            layout3.setVisibility(View.GONE);
            layout4.setVisibility(View.VISIBLE);
            textNameVal.setVisibility(View.GONE);
            text1.setVisibility(View.GONE);
            buttonUpload.setVisibility(View.GONE);

            int x=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
            int y=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());         
            cropView.of(filePath).withAspect(x,y).initialize(StudentDetails.this);
        }
        }

这是我从库中选择图像然后裁剪它的代码。如何实现代码打开相机并捕获图像,然后在同一代码中应用裁剪。

我尝试使用此代码,但没有用:

 Intent intent = new Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");
            startActivityForResult(intent, REQUEST_PICK);

我已经使用https://github.com/oginotihiro/cropview进行裁剪。我想以与固定尺寸的cropview中的运动图像相同的方式裁剪图像。现在我如何通过从相机捕获来裁剪图像。请帮助我。

1 个答案:

答案 0 :(得分:0)

有多种方式可供您使用......

访问此链接并逐步找到解决方案..

Click here for it...