2017-02-27 63 views
-1

enter image description here的Android專用相機,在風景拍攝的照片得到了收縮

我DONOT有肖像isssue,風景它得到了收縮

+0

必須已某處定義的畫面的縱橫比或像素組合。如果不查看用於拍攝照片的代碼,就會有所幫助。 –

+0

Camera.Size previewSize = parameters.getSupportedPreviewSizes()。get(0); (Camera.Size size:parameters.getSupportedPreviewSizes()){ if 休息; } } parameters.setPreviewSize(previewSize.width,previewSize.height); –

+0

這是我用於預覽大小的代碼。實際上,我將圖片從風景旋轉到了portrait.i,在旋轉圖片時出現了問題 –

回答

0
Actually,i facing problem in rotating a taken picture.if i took picture in ortrait or portrait inverted.=,picture taken was awesome.but if i took picture in landscape /inverted landscape,my captured image got shrinked,i posted below code about orientation shrinking issue.its not about preview shrinking. 
    Camera.PictureCallback mPicture = new Camera.PictureCallback() { 
     @Override 
     public void onPictureTaken(byte[] data, Camera camera) { 
      Const.image_type = "image"; 
      scanFile(Const.image_file.getAbsolutePath()); 
      // Intent intent = new Intent(getContext(), Publish_View.class); 
      Intent intent = new Intent(getContext(), PhotoPreview.class); 
      intent.putExtra("filepath", Const.image_file.getAbsolutePath()); 
      intent.putExtra("videofilepath", ""); 
      // intent.putExtra("picture", ""); 
      intent.putExtra("gallery", ""); 
      startActivity(intent); 
      getActivity().finish(); 
      isFlashOn = false; 
      //turnOffFlash(); 

      if (pictureFile == null) { 
       safeToTakePicture = true; 
       return; 
      } 

      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inSampleSize = 6; 
      options.inDither = false; 
      options.inPurgeable = true; 
      options.inInputShareable = true; 
      options.inTempStorage = new byte[32 * 1024]; 
      options.inPreferredConfig = Bitmap.Config.RGB_565; 
      Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, data.length, options); 
      int orientation; 
      if (bMap.getHeight() < bMap.getWidth()) { 
       orientation = setOrientation; 
      } else { 
       orientation = setOrientation; 
      } 

      Bitmap bMapRotate; 
      if (orientation != 0) { 
       Matrix matrix = new Matrix(); 
       matrix.postRotate(orientation); 
       bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true); 
      } else { 
       bMapRotate = Bitmap.createScaledBitmap(bMap, bMap.getWidth(), bMap.getWidth(), true); 
      } 
      try { 
       FileOutputStream out = new FileOutputStream(pictureFile); 
       bMapRotate.compress(Bitmap.CompressFormat.JPEG, 100, out); 
       if (bMapRotate != null) { 
        bMapRotate.recycle(); 
        bMapRotate = null; 
       } 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      mCamera.startPreview(); 
      safeToTakePicture = true; 
      isFlashOn = false; 
      isFrontCam = false; 
      image_staus = false; 
     } 
    }; 


    private class SimpleOrientationEventListener extends OrientationEventListener { 

     public SimpleOrientationEventListener(Context context) { 
      super(context, SensorManager.SENSOR_DELAY_NORMAL); 
     } 


     @Override 
     public void onOrientationChanged(int orientation) { 
      // We keep the last known orientation. So if the user first orient 
      // the camera then point the camera to floor or sky, we still have 
      // the correct orientation. 
//   if (orientation == ORIENTATION_UNKNOWN) return; 
//   mOrientation = Util.roundOrientation(orientation, mOrientation); 
//   // When the screen is unlocked, display rotation may change. Always 
//   // calculate the up-to-date orientationCompensation. 
//   int orientationCompensation = mOrientation 
//     + Util.getDisplayRotation(getActivity()); 
//   if (mOrientationCompensation != orientationCompensation) { 
//    mOrientationCompensation = orientationCompensation; 
//    mFaceView.setOrientation(mOrientationCompensation); 
//    Log.d("fkjkf","gkjksjgj"); 
// 
//   } 


      // determine our orientation based on sensor response 
      int lastOrientation = mOrientation; 

      if (orientation >= 315 || orientation < 45) { 
       if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) { 
        mOrientation = ORIENTATION_PORTRAIT_NORMAL; 
       } 
      } else if (orientation < 315 && orientation >= 225) { 
       if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) { 
        mOrientation = ORIENTATION_LANDSCAPE_NORMAL; 
       } 
      } else if (orientation < 225 && orientation >= 135) { 
       if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) { 
        mOrientation = ORIENTATION_PORTRAIT_INVERTED; 
       } 
      } else { // orientation <135 && orientation > 45 
       if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) { 
        mOrientation = ORIENTATION_LANDSCAPE_INVERTED; 
       } 
      } 

      if (lastOrientation != mOrientation) { 
       changeRotation(mOrientation); 
       Log.d("checktry", String.valueOf(mOrientation)); 
       mFaceView.setOrientation(mOrientation); 
      } 
     } 
    } 


private void changeRotation(int orientation) { 
     switch (orientation) { 
      case ORIENTATION_PORTRAIT_NORMAL: 

       if (isFrontCam) { 
        setOrientation = 270; 
        Log.v("CameraActivity", "Orientation = 270"); 
       } else { 
        setOrientation = 90; 
        Log.v("CameraActivity", "Orientation = 90"); 
       } 
       break; 
      case ORIENTATION_LANDSCAPE_NORMAL: 
       if (isFrontCam) { 
        setOrientation = 0; 
        Log.v("CameraActivity", "Orientation = 0"); 
       } else { 
        Log.v("CameraActivity", "Orientation = 0"); 
        setOrientation = 0; 
       } 

       break; 
      case ORIENTATION_PORTRAIT_INVERTED: 
       if (isFrontCam) { 
        setOrientation = 90; 
        Log.v("CameraActivity", "Orientation = 90"); 
       } else { 
        Log.v("CameraActivity", "Orientation = 270"); 
        setOrientation = 270; 
       } 

       break; 
      case ORIENTATION_LANDSCAPE_INVERTED: 
       if (isFrontCam) { 
        setOrientation = 180; 
        Log.v("CameraActivity", "Orientation = 180"); 
       } else { 
        Log.v("CameraActivity", "Orientation = 180"); 
        setOrientation = 180; 
       } 

       break; 
     } 
    } 
+0

這不是一個答案。您需要在問題中發佈您的代碼。 –

+0

@AlexCohn ok.let幫助我。 –

+0

糾正我,如果我錯了,但你不應用旋轉矩陣,如果圖片是風景,是嗎? –

0

這是用於表面觀

@覆蓋 公共無效代碼surfaceChanged(SurfaceHolder holder,int format,int width,int height)if(holder.getSurface()== null){ return; } strong text try { mCamera.stopPreview(); (例外e){ } mSupportedPreviewSizes = mCamera.getParameters()。getSupportedPreviewSizes(); (Camera.Size str:mSupportedPreviewSizes) Log.e(TAG,str.width +「/」+ str.height); 嘗試Camera.Parameters parameters = mCamera.getParameters();

 Camera.Size previewSize = parameters.getSupportedPreviewSizes().get(0); 
     for (Camera.Size size : parameters.getSupportedPreviewSizes()) { 
      if (size.width >= cameraLayout.getLayoutParams().width && size.height >= cameraLayout.getLayoutParams().height) { 
       previewSize = size; 
       break; 
      } 
     } 
     parameters.setPreviewSize(previewSize.width, previewSize.height); 
     List<Camera.Size> sizes = parameters.getSupportedPictureSizes(); 
     int w = 0, h = 0; 
     for (Size size : sizes) { 
      if (size.width > w || size.height > h) { 
       w = size.width; 
       h = size.height; 
      } 
     } 
     parameters.setPictureSize(w, h); 
     List<String> focusModes = parameters.getSupportedFocusModes(); 
     if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) 
      parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); 
     parameters.setJpegQuality(100); 
     mCamera.setParameters(parameters); 
    } catch (Exception e) { 
    } 
    setDisplayOrientation(); 
    setErrorCallback(); 
    mCamera.startPreview(); 
} 
相關問題