gpt4 book ai didi

java - 如何在不同的 ImageView 中设置不同的裁剪图像

转载 作者:行者123 更新时间:2023-12-01 18:34:15 27 4
gpt4 key购买 nike

当我添加第一个图像时,它会被裁剪并显示到第一个 ImageView 中,但是当我添加第二个图像时,它会覆盖第一个 ImageView 中存在的第一个图像,而不是它应该显示在第二个 ImageView 中。

Problem is shown here

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode== 0 && resultCode == RESULT_OK && data != null && data.getData() !=null){
Imageuri = data.getData();
CropImage.activity(Imageuri).setGuidelines(CropImageView.Guidelines.ON).start(AddaddNewProductActivity.this);
}
else if (requestCode== 1 && resultCode == RESULT_OK && data != null && data.getData() !=null){
Imageuri = data.getData();
CropImage.activity(Imageuri).setGuidelines(CropImageView.Guidelines.ON).start(AddaddNewProductActivity.this);
}
else if (requestCode== 2 && resultCode == RESULT_OK && data != null && data.getData() !=null){
Imageuri = data.getData();
CropImage.activity(Imageuri).setGuidelines(CropImageView.Guidelines.ON).start(AddaddNewProductActivity.this);
}

if ( requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){
Image.setBackground(null);
CropImage.ActivityResult result = CropImage.getActivityResult(data);
croppedImageUri = result.getUri();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), croppedImageUri);
Image.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void showImageChooser(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 0);
}

private void showImageChooser1(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
}

private void showImageChooser2(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 2);
}

最佳答案

我认为您仅在一个 ImageView 中设置了所有图像,因此出现了此问题,我对您的代码进行了一些更改,请检查下面的天气是否正常工作。

// First declare one variable to identify which imageview is clicked
int currentSelectedImage = 0;


@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 0 || requestCode == 1 || requestCode == 2) && resultCode == RESULT_OK && data != null && data.getData() !=null){
currentSelectedImage = requestCode;
Imageuri = data.getData();
CropImage.activity(Imageuri).setGuidelines(CropImageView.Guidelines.ON).start(AddaddNewProductActivity.this);
}

if ( requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){

CropImage.ActivityResult result = CropImage.getActivityResult(data);
croppedImageUri = result.getUri();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), croppedImageUri);

if(currentSelectedImage == 0)
{
Image.setBackground(null);
Image.setImageBitmap(bitmap);
}
else if(currentSelectedImage == 1)
{
Image1.setBackground(null);
Image1.setImageBitmap(bitmap);
}
else if(currentSelectedImage == 2)
{
Image2.setBackground(null);
Image2.setImageBitmap(bitmap);
}


} catch (IOException e) {
e.printStackTrace();
}
}
}

关于java - 如何在不同的 ImageView 中设置不同的裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60091746/

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