简体   繁体   English

如何固定裁剪突出显示视图的高度,而不是使用上载的图像进行更改?

[英]How to Fix the Height of the Cropping Highlighted View, instead of changing using uploaded Image?

I am using the following sample code, https://github.com/mklimek/android-crop/tree/newfeature_fied_size_crop . 我正在使用以下示例代码https://github.com/mklimek/android-crop/tree/newfeature_fied_size_crop It is giving the fixed size cropping view(ie, HighlightView). 它提供了固定大小的裁剪视图(即HighlightView)。 But the problem is this highlightView is fixed depends on Uploaded image. 但是问题在于,highlightView是固定的,取决于上载的图像。 Below are the screen shots with two different size uploaded images. 以下是带有两个不同尺寸的上传图像的屏幕截图。

I used below lines of code to fix the size of the HighlightView: 我使用以下代码行来固定HighlightView的大小:

 private void beginCrop(Uri source) {
    Uri outputUri = Uri.fromFile(new File(getCacheDir(), "cropped"));
    new Crop(source).output(outputUri).asRectangle().withFixedSize(100, 210).start(this);
 }

withFixedSize() method is used to fix the size of the cropped area , we cannot resize that view if we use this method, that is fine. withFixedSize()方法用于固定裁剪区域的大小,如果使用此方法,则无法调整该视图的大小,这很好。 But That cropped area should be fixed with width=100, height=210,It should not change depends the uploaded image. 但是裁切后的区域应固定为width = 100,height = 210,它不应更改,取决于上传的图像。

Big size uploaded image has a small size of crop view (ie, HighlightView): 大尺寸上传的图片的裁切视图尺寸较小(即HighlightView):

在此处输入图片说明

Small size uploaded image has a large size of crop view (ie, HighlightView): 上传尺寸较小的图片具有较大的裁切视图尺寸(即HighlightView):

在此处输入图片说明

My requirement is I have to fix the size of cropped area, I should not resize that. 我的要求是我必须固定裁剪区域的大小,而不应该调整大小。 I searched in google world. 我在谷歌世界搜索。 But I didn't found solution. 但是我没有找到解决方案。

Please help me on this. 请帮我。

visit this : https://github.com/jdamcd/android-crop 访问此: https : //github.com/jdamcd/android-crop

Crop 作物

Crop.of(inputUri, outputUri).asSquare().start(activity)

Listen for the result of the crop (see example project if you want to do some error handling): 监听裁剪的结果(如果要执行一些错误处理,请参见示例项目):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
    if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
        doSomethingWithCroppedImage(outputUri);
    }
}

Some attributes are provided to customise the crop screen. 提供了一些属性以自定义裁剪屏幕。 See the example project theme. 请参阅示例项目主题。

Pick

The library provides a utility method to start an image picker: 该库提供了一种实用程序方法来启动图像选择器:

Crop.pickImage(activity)

Dependency 相依性

The AAR is published on Maven Central: AAR在Maven Central上发布:

compile 'com.soundcloud.android:android-crop:1.0.1@aar'

Java code : Java代码:

public class MainActivity extends Activity {

    private ImageView resultView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        resultView = (ImageView) findViewById(R.id.result_image);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_select) {
            resultView.setImageDrawable(null);
            Crop.pickImage(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent result) {
        if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
            beginCrop(result.getData());
        } else if (requestCode == Crop.REQUEST_CROP) {
            handleCrop(resultCode, result);
        }
    }

    private void beginCrop(Uri source) {
        Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
        Crop.of(source, destination).asSquare().start(this);
    }

    private void handleCrop(int resultCode, Intent result) {
        if (resultCode == RESULT_OK) {
            resultView.setImageURI(Crop.getOutput(result));
        } else if (resultCode == Crop.RESULT_ERROR) {
            Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
        }
    }

}

Output : 输出:

在此处输入图片说明

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

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