Feb 5, 2015

Android ImageView


 
There are 3 ways of get the image.

First, take a picture!

Second, get the picture in gallery!

Last is loading drawable image.

Run my example app.




Click to finger image!!

You can see  alertDialog.



You can choose how to get image.

This is Dialog code.

  1.         AlertDialog.Builder ad=new AlertDialog.Builder(this);
  2.         ad.setTitle("How to get picture?")
  3.                 .setMessage("Click to button!!")
  4.                 .setPositiveButton("Take a picture!",new DialogInterface.OnClickListener() {
  5.                     @Override
  6.                     public void onClick(DialogInterface dialog, int which) {
  7.                         Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  8.                         startActivityForResult(intent, intent_camera);
  9.                     }
  10.                 })
  11.                 .setNegativeButton("Getting the Gallery!",new DialogInterface.OnClickListener() {
  12.                     @Override
  13.                     public void onClick(DialogInterface dialog, int which) {
  14.                         Intent intent=new Intent();
  15.                         intent.setAction(Intent.ACTION_GET_CONTENT);
  16.                         intent.setType("image/-");
  17.                         startActivityForResult(intent, intent_gallery);
  18.                     }
  19.                 })
  20.                 .setNeutralButton("Getting the basic image",new DialogInterface.OnClickListener() {
  21.                     @Override
  22.                     public void onClick(DialogInterface dialog, int which) {
  23.                         showPicture.setImageResource(R.drawable.click);
  24.                     }
  25.                 })
  26.                 .show();
Line 8~9 : run Camera!!

Line 16~19 : run Gallery.

Line 25 : get the drawable image!!

In case of camera & gallery,
You must use  'startActivityForResult' and 'onActivityResult'

Picture uri  is use  data.getData();

  1. Uri uri= data.getData();
  2. showPicture.setImageURI(uri);








No comments:

Post a Comment