Android 如何找到安卓相机的焦距?
我用stackoverflow和google搜索了很多东西。我需要计算相机和指定对象之间的距离 为此,我需要找到我相机的焦距。我也创建了示例项目,但创建空指针异常。请帮助 代码如下Android 如何找到安卓相机的焦距?,android,android-camera,Android,Android Camera,我用stackoverflow和google搜索了很多东西。我需要计算相机和指定对象之间的距离 为此,我需要找到我相机的焦距。我也创建了示例项目,但创建空指针异常。请帮助 代码如下 public class MainActivity extends Activity { Camera mcamera; int focul_length; Parameters params; File mFile; public int PICTURE_ACTI
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;
}
}
您正在初始化摄影机对象吗?在您的
onCreate()中尝试类似的操作
有可能吗?祝你好运是的,这是绝对可能的…使用android.hardware.camera.Parameters类。但是我无法让它工作:(谢谢它工作了。)现在你能引导我找到仰角吗??
mcamera = Camera.open();