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

This is my code for selecting image from gallery and then crop it.How implement code to open camera and capture image and then apply crop in this same code.

I tried using this code,but of no use:

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

I have used https://github.com/oginotihiro/cropview for cropping.I want to crop image in the same manner that is with moving image inside cropview with fixed dimension.Now how can I crop the image by capturing from camera.Please help me.

Amshu
  • 127
  • 10
  • here is one solution, I hope it will work for you http://stackoverflow.com/questions/25490928/androidselect-image-from-gallery-then-crop-that-and-show-in-an-imageview][1] – GS Nayma Aug 04 '16 at 12:35
  • if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) { filePath = data.getData(); Bitmap photo = (Bitmap) data.getExtras().get("data"); resultIv.setImageBitmap(photo); 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); } Image is not displaying here. – Amshu Aug 04 '16 at 12:56

1 Answers1

0

There are multiple ways available for you...

visit this link and go step by step for your solution..

Click here for it...

Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
  • I dont want to crop in this way.Please go through https://github.com/oginotihiro/cropview link.I want to crop the image in that way. – Amshu Aug 04 '16 at 11:38
  • all the thing are same.. for it you have to read documentation of github.com/oginotihiro/cropview and go throught it.... – Rajesh Satvara Aug 04 '16 at 11:41
  • Then can you tell me how can I implent.I have seen all this and am not able to use it my code. – Amshu Aug 04 '16 at 11:46
  • All d things are available over there... just you have to pass URI into step no 3. – Rajesh Satvara Aug 04 '16 at 11:49
  • if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) { filePath = data.getData(); Bitmap photo = (Bitmap) data.getExtras().get("data"); resultIv.setImageBitmap(photo); 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); } Image is not displaying here. – Amshu Aug 04 '16 at 12:53