Reputation: 1161
In my app I have a button which opens camera and captures image.When I capture the image I set it in ImageView.
I want to add a feature like whatsapp profile pics like when I click on the image it enlarges.
For that I have set an onclicklistner
to the ImageView and defined a dialog.
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Dialog imagedialog = new Dialog(MainActivity.this);
imagedialog.setContentView(R.layout.imagedialog);
ImageView photo = (ImageView) imagedialog.findViewById(R.id.photoenlarge);
}
});
In that dialog I have a ImageView which will show the enlarged image.
My camera code:
btncapture.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,CAMERA_REQUEST);
}
});
Code of onActivityResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
In the imageView.setOnClickListener
method how can I set ImageView photo
with the captured image??
Upvotes: 0
Views: 391
Reputation: 1354
Instead of using a dialog you can follow this guide from the android docs to do it. What it does is having 2 imageviews on the same page, with the one showing the image at full size hidden, when clicking on the small one, the big one is shown with an animation.
Upvotes: 2
Reputation: 18765
You have to something like this
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Dialog imagedialog = new Dialog(MainActivity.this);
imagedialog.setContentView(R.layout.imagedialog);
ImageView photo = (ImageView) imagedialog.findViewById(R.id.photoenlarge);
// get the applied image from the imageview as a bitmap
Bitmap image=((BitmapDrawable)imageView.getDrawable()).getBitmap();
// set bitmap image to dialog image view
photo.setImageBitmap(image);
imagedialog.show();
}
});
Upvotes: 0