How can I add two images on two separate image views with two different buttons?
如何使用两个不同的按钮在两个单独的图像视图上添加两个图像?
I used the below code for cropping and setting the image, for just a single button and single image view.
我使用下面的代码进行裁剪和设置图像,只需一个按钮和单个图像视图。
So what should I do for the two separate image views with two separate buttons on single screen?
那么,对于单个屏幕上有两个独立按钮的两个独立图像视图,我该怎么做?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0 && resultCode == RESULT_OK)
CropImage();
else if(requestCode == 2)
{
if(data != null)
{
uri = data.getData();
CropImage();
}
}
else if (requestCode == 1)
{
if(data != null)
{
Bundle bundle = data.getExtras();
Bitmap bitmap = bundle.getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.imgHead);
imageView.setImageBitmap(bitmap);
}
}
}
private void CropImage() {
try{
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri,"image/*");
CropIntent.putExtra("crop","true");
CropIntent.putExtra("outputX",180);
CropIntent.putExtra("outputY",180);
CropIntent.putExtra("aspectX",3);
CropIntent.putExtra("aspectY",3);
CropIntent.putExtra("scaleUpIfNeeded",true);
CropIntent.putExtra("return-data",true);
startActivityForResult(CropIntent,1);
}
catch (ActivityNotFoundException ex)
{
}
}
private void GalleryOpen() {
GalIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2);
}
1 个解决方案
#1
1
You can keep a global boolean variable buttonOne and set it to a default value of false. Now, if buttonOne is clicked, set buttonOne =True
. After that, in your onActivityResult()
method, add another conditional statement
您可以保留全局布尔变量buttonOne并将其设置为默认值false。现在,如果单击buttonOne,请设置buttonOne = True。之后,在onActivityResult()方法中,添加另一个条件语句
if (buttonOne){
imageViewOne.setImage();
}
else if(!buttonOne){
imageViewTwo.setImage();
}
I hope this will work, if I understood your problem correctly.
如果我理解你的问题,我希望这会奏效。
#1
1
You can keep a global boolean variable buttonOne and set it to a default value of false. Now, if buttonOne is clicked, set buttonOne =True
. After that, in your onActivityResult()
method, add another conditional statement
您可以保留全局布尔变量buttonOne并将其设置为默认值false。现在,如果单击buttonOne,请设置buttonOne = True。之后,在onActivityResult()方法中,添加另一个条件语句
if (buttonOne){
imageViewOne.setImage();
}
else if(!buttonOne){
imageViewTwo.setImage();
}
I hope this will work, if I understood your problem correctly.
如果我理解你的问题,我希望这会奏效。