gpt4 book ai didi

android - 如何找到android相机的焦距?

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:17 25 4
gpt4 key购买 nike

我使用 stackoverflow 和 google 搜索了很多。我需要计算我的相机和指定对象之间的距离。

为此,我需要找到相机的焦距。我也创建了示例项目,但它创建了 Null Pointer Exception。请帮忙..

代码如下。

    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;
}

}

最佳答案

您是否正在初始化 Camera 对象?在你的 onCreate()

中尝试这样的事情
mcamera = Camera.open();

关于android - 如何找到android相机的焦距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18531896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com