【问题标题】:crop image by taking photo from camera通过从相机拍照来裁剪图像
【发布时间】:2016-12-10 12:07:20
【问题描述】:
 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 进行裁剪。我想以与固定尺寸的裁剪视图内的移动图像相同的方式裁剪图像。现在如何通过从相机捕获来裁剪图像。请帮助我。

【问题讨论】:

  • 这里有一个解决方案,我希望它对你有用stackoverflow.com/questions/25490928/…
  • if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) { filePath = data.getData();位图照片 = (位图) data.getExtras().get("data"); resultIv.setImageBitmap(照片); 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); } 图片未在此处显示。

标签: android


【解决方案1】:

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

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

Click here for it...

【讨论】:

  • 我不想以这种方式裁剪。请通过github.com/oginotihiro/cropview链接。我想以这种方式裁剪图像。
  • 所有的东西都是一样的......为此你必须阅读 github.com/oginotihiro/cropview 的文档并仔细阅读......
  • 那你能告诉我我该怎么做。我已经看到了这一切,但我的代码无法使用它。
  • 那里所有的东西都可用...只是您必须将 URI 传递到第 3 步。
  • if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) { filePath = data.getData();位图照片 = (位图) data.getExtras().get("data"); resultIv.setImageBitmap(照片); 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); } 图片未在此处显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多