2013-08-30 43 views
4

我已經使用stackoverflow和google.I進行了很多操作,我需要計算我的相機和指定對象之間的距離。如何找到android相機的焦距?

對於我需要找到我的我的camera.I的焦距創建示例項目還,但其創造空指針Exception.Please幫助..

的代碼如下。

public class MainActivity extends Activity { 

    Camera mcamera; 
    int focul_length; 
    Parameters params; 
    File mFile; 

    public int PICTURE_ACTIVITY_CODE = 1; 
    public String FILENAME = "sdcard/photo.jpg"; 
    Camera.Parameters cameraParameters; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     launchTakePhoto(); 

    } 

    private void launchTakePhoto() 
    { 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      cameraParameters = mcamera.getParameters(); 
     CameraInfo myinfo = new CameraInfo(); 
    float l=cameraParameters.getFocalLength(); // Here its creating Null Pointer Exception  
    mFile = new File(FILENAME); 
      System.out.println("My Focul Length:--"+l); 
    Uri outputFileUri = Uri.fromFile(mFile); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
    startActivityForResult(intent, PICTURE_ACTIVITY_CODE); 
    } 


    Also If possible please provide the code to get angle of Elevation.If possible.I need this very badly.I need your help guys!! 



    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
     { 
      if (requestCode == PICTURE_ACTIVITY_CODE) 
      { 
      if (resultCode == RESULT_OK) 
      { 

      ImageView myimageView = (ImageView) findViewById(R.id.imageView1); 
      Uri inputFileUri = Uri.fromFile(mFile); 
      myimageView.setImageURI(inputFileUri); 
      } 
      } 
      } 






    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 
+0

它甚至有可能嗎?祝你好運 !! –

+0

是的,它絕對有可能...使用android.hardware.camera.Parameters類。但我無法使事情工作:( – Chiradeep

回答

1

您是否正在初始化Camera對象?嘗試這樣的事情在你的onCreate()

mcamera = Camera.open(); 
+0

感謝它的工作..現在可以指導我找到仰角?? – Chiradeep

+0

http ://developer.android.com/reference/android/hardware/Camera.Parameters.html#getVerticalViewAngle() – Nachi