仅肖像图片

时间:2014-09-26 22:13:43

标签: android android-camera

我有一个自定义相机活动,只能在纵向模式下拍照,但在三星设备中,图片总是以横向模式显示在我的nexus设备上,图片在纵向模式下正确显示。以下是我设置相机参数和方向的方法。这个initPreview是在SurfaceHolder.Callback surfaceChanged方法中调用的。

 /** INITIALIZE THE PREVIEW PARAMTERS */
 private void initPreview(int width, int height) {
    if ( mCamera != null && previewHolder.getSurface() != null) {
        try {
            mCamera.setPreviewDisplay( previewHolder );
        }
        catch (Throwable t) {
            Log.e("PreviewDemo-surfaceCallback", "Exception in setPreviewDisplay()", t);
            Crouton.makeText( this, t.getMessage(), Style.ALERT ).show();
        }

        if (!cameraConfigured) {
            Camera.Parameters parameters = mCamera.getParameters();
            Camera.Size size = getBestPreviewSize(width, height, parameters);
            Camera.Size pictureSize = getSmallestPictureSize(parameters);

            if (size != null && pictureSize != null) {
                parameters.setPreviewSize( size.width, size.height );
                parameters.setPictureSize( pictureSize.width, pictureSize.height );
                parameters.setPictureFormat( ImageFormat.JPEG);

                parameters.set( "orientation", "portrait" );
                parameters.setRotation( 90 );
                mCamera.setDisplayOrientation( 90 );
                mCamera.setParameters( parameters );
                cameraConfigured = true;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

background

三星在这方面有缺陷。你可以试试这个......

获取将照片网址与存在问题的三星隔离的方向......

public static int getOrientation(Context context, Uri photoUri) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor.getCount() != 1) {
        return -1;
    }

    cursor.moveToFirst();
    return cursor.getInt(0);
}

确定后,请执行位图旋转以更正Samsung问题...

                            if( getOrientation(ctx, photoUrl) == 0 ||  getOrientation(ctx, photoUrl) == -1){
                                //not samsung issue so process as normal;
                            }else{  // bad samsung needs rotation

                                Bitmap lbit =   
                                BitmapFactory.decodeStream(
                                        getContentResolver().openInputStream(_photo_uri),null,options);

                                lbit = lbit.copy(Bitmap.Config.ARGB_8888, true);
                                Matrix matrix = new Matrix();
                                matrix.postRotate(intReturnFromGetOrientationCall);
                                lbit = Bitmap.createBitmap(lbit, 0, 0, lbit.getWidth(),
                                        lbit.getHeight(), matrix, true);
                                Picture.setBmp(lbit);
                            }