Some image sizes causing Camera.takePicture () error

Summary: Explicitly setting the camera image size to a supported size causes callbacks that cannot be called after calling the Camera.takePicture () function for some image sizes.

Details:

I am working on a simple camera application that uses the camera API to capture images. It follows the principles described in the camera class documentation and works reliably on various devices.

After calling Camera.open (), the application calls camera.getParameters () to get the Camera.Parameters object, and then calls this getSupportedPictureSizes () object. It iterates over the supported image sizes and selects a pair of the same size that matches some criteria. Then it calls setPictureSize (), passing the selected width and height. Finally, it sets the camera parameters by calling the Camera.SetParameters () function, passing the Camera.Parameters object.

I'm having problems with HTC Desire 620. One of the supported image sizes reported on this device is 1184x1184. If I set this image size and then call the camera.takePicture () function, none of the callbacks (shutter, raw or jpeg) will be called and the camera object will be in an invalid state. If I explicitly set the image size to any other supported size (square or rectangular aspect ratio), then callbacks are called. But for 1184x1184 they are not.

Has anyone come across something similar? Is there a way to know in advance whether the supported image size will cause this type of problem? What am I missing here?

Edit: typo

+4
source share
2 answers

HTC Desire 620, . Android-. , , , . Honeycomb 2.3, . .

, Galaxy Nexus , QVGA getSupportedPreviewSizes(). . 320x240 - 640x480 onPreviewFrame().

. . .

, , , . - camera.setParameters() try... catch.

: , . , API- , , ​​.

, , , ( ) .

, , . . 16: 9, 4: 3.

- Samsung Galaxy S3. 1001.

+1

, . , , , .

:

 private static final int CAMERA_PIC_REQUEST = 2500;
private Rect Padding = new Rect(-1,-1,-1,-1);
private Matrix matrix = new Matrix();
private Bitmap rotatedBitmap = null;
private Bitmap bm = null;
private Bitmap scaledBitmap= null;
private ExifInterface exif ;
private int rotation=0;
private final BitmapFactory.Options options = new BitmapFactory.Options();

, , , (Mine )

btn_camera.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {

              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

          }
    }
    );

, CAMERA _PIC_REQUEST OnActivityResult()

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_PIC_REQUEST)
        if (data != null) {
        imageuri = data.getData();
        //Bitmap image = (Bitmap) data.getExtras().get("data");

        try {
            options.inSampleSize = 2;
            exif = new ExifInterface(getRealPathFromURI(imageuri));
            rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            rotation = exifToDegrees(rotation);

            bm = BitmapFactory.decodeStream(
                    getActivity().getContentResolver().openInputStream(imageuri),Padding,options);

            scaledBitmap = Bitmap.createScaledBitmap(bm, 400,400, true);

            if (rotation != 0)
            {matrix.postRotate(rotation);}
            //matrix.postRotate(180);
            rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        mIvFoto.setImageBitmap(rotatedBitmap);


     }
 }

, ImageView, , . . . ScaledBitmap, , ScaledBitmap, , 400 400 , , , , .

, , .

private static int exifToDegrees(int exifOrientation) {
    if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
    else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {  return 180; }
    else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {  return 270; }
    return 0;
}

private String getRealPathFromURI(Uri contentURI) {
    String result;
    Cursor cursor =getActivity().getContentResolver().query(contentURI, null, null, null, null);
    if (cursor == null) { // Source is Dropbox or other similar local file path
        result = contentURI.getPath();
    } else {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;
}

, .

0

All Articles