2012-01-20 15 views
0

を開くには、surfaceholderコールバッククラスクリックピクチャーが、私はそれSDカードからそれを開いたときに、ここでランドスケープモードで

class Preview implements SurfaceHolder.Callback { 
     SurfaceHolder mHolder; 


     Preview(Context context) { 
      // InstaImageButtonll a SurfaceHolder.Callback so we get notified when the 
      // underlying surface is created and destroyed. 
      try { 
       mHolder = sview.getHolder(); 
       mHolder.addCallback(this); 
       mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(), "Preview "+e.toString()+"\n"+e.getMessage(), Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 
     } 

     public void surfaceCreated(SurfaceHolder holder) { 
      // The Surface has been created, acquire the camera and tell it where 
      // to draw. 
     try { 
      mCamera = Camera.open(); 
      mCamera.setDisplayOrientation(90); 
      mCamera.setPreviewDisplay(holder); 
      Camera.Parameters params= mCamera.getParameters(); 
      params.set("jpeg-quality", 72); 
      params.setPictureFormat(PixelFormat.JPEG); 
      params.setPictureSize(480, 640); 
      mCamera.setParameters(params); 



     } catch (Exception e) { 
      Toast.makeText(TestCameraOverlay.this, 
        " surfaceCreated" + e.getMessage(), Toast.LENGTH_LONG) 
        .show(); 
      e.printStackTrace(); 
     } 
     } 

     public void surfaceDestroyed(SurfaceHolder holder) { 
      // Surface will be destroyed when we return, so stop the preview. 
      // Because the CameraDevice object is not a shared resource, it's very 
      // important to release it when the activity is paused. 
      try { 
       mCamera.stopPreview(); 
       mCamera.setPreviewCallback(null); 
       mCamera.release(); 
       mCamera = null; 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),"surfaceDestroyed "+ e.toString()+"\n"+e.getMessage(), Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 
     } 

     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
      // Now that the size is known, set up the camera parameters and begin 
      // the preview. 
      try { 
       Camera.Parameters parameters = mCamera.getParameters(); 
       parameters.setPreviewSize(w, h); 
       mCamera.setParameters(parameters); 
       mCamera.startPreview(); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),"surfaceChanged "+ e.toString()+"\n"+e.getMessage(), Toast.LENGTH_LONG).show(); 

       e.printStackTrace(); 
      } 
     } 

    } 

、ここでは私のコードは私のコードは、SDカードに撮影した画像を保存することです。

Camera.PictureCallback mPictureCallback =新しいCamera.PictureCallback(){

 public void onPictureTaken(byte[] imageData, Camera c) { 
      try { 

       File fileOnSD=Environment.getExternalStorageDirectory(); 
       File file=new File(fileOnSD.getAbsolutePath(), "testImage.jpeg"); 
       Toast.makeText(getApplicationContext(),file.getAbsolutePath()+"\n"+imageData, Toast.LENGTH_LONG).show(); 
       FileOutputStream fout=new FileOutputStream(file, false); 
       fout.write(imageData); 
       Thread.sleep(2000); 
       mCamera.startPreview(); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),"onPictureTaken " +e.toString(), Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 
     } 
     }; 

画像はその後、別の向きで撮影した画像の向きを記憶している理由を私は得ていないのです。

+0

これは、いくつかのHTCの携帯電話と私のドロイドX2など、さまざまな携帯電話、バグです。これはハードウェアの問題であり、アンドロイドはそれを修正するためにパッチを当てることはできません。コード内でイメージを回転させるだけです。 –

答えて

0

はあなたのコードでやっているすべてはsetDisplayOrientationでディスプレイを回転しているので、カメラ

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setRotation%28int%29

のsetRotationを使用してみてください。あまりにもあなたのデバイスのバージョンに依存する場合があり、このスレッドを参照してください。

How to set Android camera orientation properly?

+0

galaxy S2を使用しています(OSバージョン2.3.4) – AAnkit

関連する問題