2

I've created my own controller to take pictures with the android camera. My problem is that the output shows a smaller image than expected. I've checked the width and height of my bitmap like this:

int w = bmp.getWidth();
int h = bmp.getHeight();

This outputs w = 480 and h = 640 which I assume is the size in pixels. This is my method for taking the picture

public void takePicture() {
        Log.i("Camera View: ", "Take Picture");
        camera.takePicture(null, null, new PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                if (null != callback) {
                    callback.onJpegPictureTaken(data, camera);

                }
            }
        });
 }

Where my Activity subscribes to this event onJpegPictureTaken

    @Override
    public void onJpegPictureTaken(byte[] data, Camera camera) {
        Intent i = new Intent(this, ImageEditing.class);
        i.putExtra("image", data);
        startActivity(i);
    }

The purpose of this is to launch a new Activity in order to edit the image, like zooming and dragging. This ImageEditing.class gets the picture like this:

flipped = flipByteArrayNintyDegress(getIntent().getExtras()
                .getByteArray("image"));

        Bitmap bmp = BitmapFactory.decodeByteArray(flipped, 0, flipped.length);
        image = (ImageView) findViewById(R.id.imageView1);
        image.setImageBitmap(bmp);
        image.setOnTouchListener(this);

I first thought that my ImageView had some restriction due to the height and width of the ImageView, but that is not the case. Here is the layout XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix"/>

</FrameLayout>

Here is the result when I capture the image

enter image description here Does anybody know what's going on here? Why is the image being scaled?

Sathyajith
  • 3,836
  • 3
  • 15
  • 28
Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143

2 Answers2

6

The data returned to onJpegPictureTaken() is intended as a thumbnail representation. You are receiving one of the sizes reported by getSupportedJpegThumbnailSizes() in the Camera.Parameters. There is not enough heap memory in your camera to send an entire full-resolution image through a byte[] array, even compressed/encoded as a Jpeg image. Therefore, the thumbnail is sent as a quick way to preview the result. You have to find the storage location of the image in order to access it at full resolution.

Furthermore, even then you will have to open it with a scale factor in the BitmapFactory.Options in order to fit it memory as a Bitmap.

Also check setPictureSize() on the Camera.Parameters and check the supported sizes available with getSupportedPictureSizes().


Let Android Take the Picture For You:

You can cause the Android System Camera Application to take a full-resolution picture and return to your Activity afterwards using examples such as this: Allow user to select camera or gallery for image. Your Activity will have access to the full-resolution saved image file after it is captured by the camera.

In order to flip or rotate this image in full resolution (which is impossible to open at that size as a Bitmap), you can modify the EXIF data describing AFine transformations. This will not modify the actual pixel data, but will change the way it gets displayed on most systems. There are several examples of how to read and write EXIF data on this site but I do not have a code example that I have used available at this time.

Community
  • 1
  • 1
David Manpearl
  • 12,362
  • 8
  • 55
  • 72
0

What about the implementation of flipByteArrayNintyDegress?

/Yaron

Yaron Reinharts
  • 213
  • 1
  • 7