Android: Can't get the size of photo taken by camera acitivity

abnormal

I wrote a camera activity as Android's guide documents says. I saved the photo, then I just want to know the width and height of this photo. But I can't get it with BitmapFactory.decodeStream. Here's my code, anybody can help me?

private PictureCallback mPictureCallback = new PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
            //save the photo
        File pictureFile = new File("/sdcard/test/test.jpg");
        if(!pictureFile.exists()) {
            try {
                pictureFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG, "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }

            //get the photo's width and height
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            InputStream is = null;
            try {
                is = new FileInputStream("/sdcard/test/test.jpg");
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            if(is != null) {
                Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
                int picWidth = bitmap.getWidth();
                try {
                    is.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }



        CameraActivity.this.setResult(RESULT_OK);
        CameraActivity.this.finish();
    }
};
athom

Is this solution working for you ?

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

//Returns null, sizes are in the options variable
BitmapFactory.decodeFile("/sdcard/image.png", options);
int width = options.outWidth;
int height = options.outHeight;
//If you want, the MIME type will also be decoded (if possible)
String type = options.outMimeType;

Source : android: get image dimensions without opening it

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android Camera: Get Picture Uri after the photo is taken

From Dev

How can I get the default size (in pixels) of a photo which will be captured through Android camera, before capturing it?

From Dev

Strange size of picture taken with Android Camera

From Dev

Can't get photo printed after camera shot

From Dev

Android - Saving photo taken from Camera , Out of memory

From Dev

How to set the size and quality of a picture taken with the android camera?

From Dev

Android - get camera photo orientation not working

From Dev

How to detect if photo was taken (camera intent)

From Dev

Photo taken through camera intent is losing on quality

From Dev

I want to read exif info in image in android. I can read exif from image in gallery but i cannot read exif photo taken from the camera

From Dev

How to find the size of iphone camera photo and how can I resize it?

From Dev

How to find the size of iphone camera photo and how can I resize it?

From Dev

Get device orientation for photos taken with Android's default camera

From Dev

Get uri of picture taken by camera

From Dev

Can't get camera code from Android docs to work

From Dev

How can I get the authorization status to Photo/Camera on IOS?

From Dev

Uncompressed size of images taken with the camera phonegap

From Dev

Upload a picture taken by the camera to a server with limited size

From Dev

Custom camera shows dark picture preview when photo taken on Nexus

From Dev

Is it possible to check if an image is taken by camera or uploaded from photo library by JavaScript?

From Dev

ImageView does not display image taken from phone camera or photo gallery

From Dev

Android get full size image from camera

From Dev

Android: Taken photo is bigger than the preview

From Dev

Getting location data for a taken photo in Android

From Dev

Android Cordova - How to draw photo taken on canvas?

From Dev

Android camera and photo picker intent

From Dev

Take full size photo from camera

From Dev

picture taken with camera doesn't resize in uiimageview

From Dev

File not exist android image taken by camera

Related Related

  1. 1

    Android Camera: Get Picture Uri after the photo is taken

  2. 2

    How can I get the default size (in pixels) of a photo which will be captured through Android camera, before capturing it?

  3. 3

    Strange size of picture taken with Android Camera

  4. 4

    Can't get photo printed after camera shot

  5. 5

    Android - Saving photo taken from Camera , Out of memory

  6. 6

    How to set the size and quality of a picture taken with the android camera?

  7. 7

    Android - get camera photo orientation not working

  8. 8

    How to detect if photo was taken (camera intent)

  9. 9

    Photo taken through camera intent is losing on quality

  10. 10

    I want to read exif info in image in android. I can read exif from image in gallery but i cannot read exif photo taken from the camera

  11. 11

    How to find the size of iphone camera photo and how can I resize it?

  12. 12

    How to find the size of iphone camera photo and how can I resize it?

  13. 13

    Get device orientation for photos taken with Android's default camera

  14. 14

    Get uri of picture taken by camera

  15. 15

    Can't get camera code from Android docs to work

  16. 16

    How can I get the authorization status to Photo/Camera on IOS?

  17. 17

    Uncompressed size of images taken with the camera phonegap

  18. 18

    Upload a picture taken by the camera to a server with limited size

  19. 19

    Custom camera shows dark picture preview when photo taken on Nexus

  20. 20

    Is it possible to check if an image is taken by camera or uploaded from photo library by JavaScript?

  21. 21

    ImageView does not display image taken from phone camera or photo gallery

  22. 22

    Android get full size image from camera

  23. 23

    Android: Taken photo is bigger than the preview

  24. 24

    Getting location data for a taken photo in Android

  25. 25

    Android Cordova - How to draw photo taken on canvas?

  26. 26

    Android camera and photo picker intent

  27. 27

    Take full size photo from camera

  28. 28

    picture taken with camera doesn't resize in uiimageview

  29. 29

    File not exist android image taken by camera

HotTag

Archive