1. Are you ready for the Galaxy S20? Here is everything we know so far!

capture an image through camara

Discussion in 'Introductions' started by Shruti Shukla, Apr 11, 2012.

  1. Shruti Shukla

    Shruti Shukla Lurker
    Thread Starter

    final String [] items = new String [] {"From Camera", "From SD Card","Exit"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
    public void onClick( DialogInterface dialog, int item ) {
    if (item == 0) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(),
    "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
    mImageCaptureUri = Uri.fromFile(file);

    try {
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PICK_FROM_CAMERA);
    } catch (Exception e) {
    e.printStackTrace();
    }

    dialog.cancel();
    } else if(item==1){
    Intent intent = new Intent();

    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);

    startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
    }
    else{
    dialog.cancel();
    ChooseAPic.this.finish();
    }
    }
    }




    /////////////////////////////////////////////////////And for getting///////////

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) return;

    Bitmap bitmap = null;
    String path = "";

    if (requestCode == PICK_FROM_FILE) {
    mImageCaptureUri = data.getData();
    path = getRealPathFromURI(mImageCaptureUri); //from Gallery

    if (path == null)
    path = mImageCaptureUri.getPath(); //from File Manager

    if (path != null)
    bitmap = BitmapFactory.decodeFile(path);
    } else {
    path = mImageCaptureUri.getPath();
    bitmap = BitmapFactory.decodeFile(path);
    }

    //bmp=bitmap;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    //bitmap.compress(Bitmap.CompressFormat.PNG, 90, bos); //compress to which format you want.
    //bitmapdata = bos.toByteArray();
    //bitmapdata = bos.toByteArray();
    bitmapdata=path;
    mImageView.setImageBitmap(bitmap);

    //bitmapdata=bitmap;

    }


    :)
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Rainy11

    Rainy11 Lurker

    thnx...working
     
  3. D-U-R-X

    D-U-R-X turbo drinker

    Hello and welcome to the forums - thanks for joining!

    You might like to check out Android Development - Android Forums as this is where other devs hang out!

    Hope you find this palce useful!
     
Loading...

Share This Page

Loading...