2

Hi I used default camera for my app but after take picture,picture size is stretched.how to get original image size using default camera.

maha m
  • 29
  • 3
  • Put the code also. If it is streching, paste your xml code also – Rahul Gupta Sep 29 '14 at 08:55
  • Intent intent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); and used Bitmap Image=(Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bos=new ByteArrayOutputStream(); Image.compress(CompressFormat.JPEG,500,bos); byte[] bitmapdata=bos.toByteArray(); in onActivityResult method to save picture – maha m Sep 29 '14 at 09:04
  • http://stackoverflow.com/questions/8232608/fit-image-into-imageview-keep-aspect-ratio-and-then-resize-imageview-to-image-d – Android Sep 29 '14 at 09:05
  • @Pragna am using default camera for taking picture but after i took picture it has stretched to both left and right side can you please tell why? – maha m Sep 29 '14 at 09:11
  • ok 1 min you mean to say in gallery it display stretched or in imageview? – Android Sep 29 '14 at 09:27
  • yes in image view it is stretched. – maha m Sep 29 '14 at 10:44

1 Answers1

0

When you take a picture from camera and when you do data.getData(), it return the thumbnail image. that is why it is streching. To get the full image , you need to pass an Uri for the image in the camera intent, to use it to get the full image.

For Example :-

try {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {

            createImageFile();

            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,userPhotoUri);
            startActivityForResult(takePictureIntent, Utils.ACTION_REQUEST_CAMERA);

        }
    } catch (Exception e) {
                    CustomizeCrouton.showCrouton("Capture Photo cannot be launched.", mContext);
}

The method createImageFile() returns an uri to be used to store the captured image :-

private void createImageFile() throws IOException {

    File image = null;

    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";

    if(MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){

        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
                );

    }else{

        File storageDir = mContext.getFilesDir();
        image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
                );

    }

    // Save a file: path for use with ACTION_VIEW intents
    Log.d(TAG,"file:" + image.getAbsolutePath());
    userPhotoUri = Uri.fromFile(image);
}

After taking the image, use that Uri to load the image. For that, there are many ways, you can google it :-

 Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
Rahul Gupta
  • 5,275
  • 8
  • 35
  • 66
  • how to convert thumbnail image into bitmap show some way please..Thanks in advance – maha m Sep 29 '14 at 10:42
  • Read my answer again. It has explained. When you take picture, by default you get a thumbnail image of size around 80 x 80 around(I dont know). To get the full image, you need to pass explicit uri which i did above and after the image is captured, that image is stored at this uri from which you can get the image in `onActivityResult` by the code i have written at the bottom of my answer – Rahul Gupta Sep 29 '14 at 10:49
  • how can i save actual image without passing uri. – maha m Sep 29 '14 at 11:05
  • You cannot. you will get a thumbnail if you don't pass uri. Pass an uri. What's the issue. – Rahul Gupta Sep 29 '14 at 12:19