gpt4 book ai didi

android - 在android中裁剪图像

转载 作者:行者123 更新时间:2023-11-30 10:33:40 26 4
gpt4 key购买 nike

我想对图像进行裁剪,我发现了一些非常有用的图像,但不知何故就像没有使未选择的区域变暗一样,所以我想知道有人知道怎么做吗?或引导我走向正确的方向?我发现的在线教程显示它会使所选区域变暗但是当我使用它时,它不会。请帮助我,非常感谢,抱歉我的英语不好。

指向我使用的教程的链接。

Crop image tutorial 1

Crop Image tutorial 2

我希望它是这样的。

I want it be something like this

editButton.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goEdit;
goEdit = new Intent(PreviewActivity.this, CropImage.class);
goEdit.putExtra("image-path", path);
goEdit.putExtra("scale", true);
goEdit.putExtra("fileName", nameFromPath);
//finish();
checkEdit = true;
startActivityForResult(goEdit,0);

}
});

编辑我使用此按钮监听器通过调用 CropImage 类 Activity 来调入 cropImage 文件。这是一个自定义 Intent ,不是 android 中的裁剪功能,但我认为是它的副本,以便使其支持所有版本,但是当我调用它时,所选区域不会变亮,我不知道问题出在哪里,有人可以指导我吗?谢谢这是我正在使用的库 drioid4you crop image

最佳答案

您可以使用默认的 android Crop 功能吗?

这是我的代码

private void performCrop(Uri picUri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties here
cropIntent.putExtra("crop", true);
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// indicate output X and Y
cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}

声明:

final int PIC_CROP = 1;

在顶部。

在onActivity的result方法中,编写如下代码:

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

if (requestCode == PIC_CROP) {
if (data != null) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap selectedBitmap = extras.getParcelable("data");

imgView.setImageBitmap(selectedBitmap);
}
}
}

这对我来说很容易实现,而且还能显示暗区。

关于android - 在android中裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42103494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com