Swetha Kaulwar
Swetha Kaulwar

Reputation: 111

How to attach the pictures that I take using the camera in my application?

I am developing an application where I use a button to load the camera and need to attach those pictures in my app. I have no problem in loading the camera but I am not able to attach those pictures that I took using the camera in my app. Can anybody give a good solution ?

Thank You(In Advance) Swetha Kaulwar.

Upvotes: 1

Views: 197

Answers (1)

Gil
Gil

Reputation: 578

i do this in my onActivityResult... i get the pic from the capture intent decrease its size and add it to a list which is later added to a custom listView... i hope this helps with your problen

if (resultCode == Activity.RESULT_OK) {

            Bundle extras = intent.getExtras();
            Bitmap bitmap = (Bitmap) extras.get("data");


             int width = bitmap.getWidth();
             Log.i("size width:", String.valueOf(width));
             int height = bitmap.getHeight();
             Log.i("size height:", String.valueOf(height));

             float widthPercent = (float) 0.8;
             float heightPercent = (float) 0.8;

             float newWidth = bitmap.getWidth() * widthPercent;
             float newHeight = bitmap.getHeight() * heightPercent;

             while (newWidth > 250 || newHeight > 250) {

             newWidth = newWidth * widthPercent;
             Log.i("size width:", String.valueOf(newWidth));
             newHeight = newHeight * heightPercent;
             Log.i("size height:", String.valueOf(newHeight));
             }




             // calculate the scale - in this case = 0.4f
             float scaleWidth = ((float) newWidth) / width;
             Log.i("new size width:", String.valueOf(scaleWidth));
             float scaleHeight = ((float) newHeight) / height;
             Log.i("new size height:", String.valueOf(scaleHeight));

             Matrix matrix = new Matrix();

             // resize the bit map
             matrix.postScale(scaleWidth, scaleHeight);

             // recreate the new Bitmap
             Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
             width, height, matrix, true);

             Log.i("new bitmap width:",
             String.valueOf(resizedBitmap.getWidth()));
             Log.i("new bitmap height:",
             String.valueOf(resizedBitmap.getHeight()));

            App.serviceCallImages.add(resizedBitmap);

            Adapter.notifyDataSetChanged();

            break;
        }

heres my camera intent code

public void OnCameraOpen(View v) {

    if (App.serviceCallImages.size() < 2) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        startActivityForResult(intent, CAPTURE_PICTURE_INTENT);
    } else {
        Toast.makeText(getApplicationContext(),    getString(R.string.MaxPics),
                Toast.LENGTH_SHORT).show();
    }

}

Upvotes: 2

Related Questions