问题描述
我是一个初学者到Java和Android,而我有推出相机有问题。 precisely我需要一个小型相机preVIEW这将是我的控制之下。 (我希望把眼前的景象在它的中间)。我想这个贴到我的项目:
<一href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Camera$p$pview.html\" rel=\"nofollow\">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Camera$p$pview.html
但也有错误的负载,经过我天真'固定',程序崩溃,在开始任何事情之前..
我尝试了很长一段时间谷歌搜索,均未成功。
是有人在的东西,只想没有问题的工作posession?一个项目将是不错:)
I'm a beginner to Java and Android, and I have a problem with launching a camera. Precisely I need a small camera preview that would be under my control. (I want to put a sight in the middle of it). I tried to paste this to my project:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.htmlBut there are loads of errors, after my naive 'fixing', program crashes, before starting anything.. I tried searching google for quite a long time, unsuccessfully.Is somebody in posession of something that would just work without problems? A project would be nice :)
在此先感谢
再见
Thanks in advanceBye
推荐答案
在您的onCreate方法,提供以下线条,
in your onCreate method, provide the below lines,
String imgName = getImageName();
startCamera(imgName);
和您的onCreate下方,提供了这些方法。你的相机准备好了。
And below your onCreate, provide these methods. your camera is ready.
private void startCamera(String ImageName) {
Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File(ImageName)));
startActivityForResult(cameraIntent, TAKE_PICTURE_WITH_CAMERA);
}
private String getImageName() {
String imgname = "";
String imgpath = "";
String strDirectory="/sdcard";
try {
imgname = String.format("%d.mp4", System.currentTimeMillis());
imgpath = strDirectoy + "/" + imgname;
File file = new File(strDirectoy);
boolean exists = file.exists();
if (!exists) {
boolean success = (new File(strDirectoy)).mkdir();
if (success)
Log.e("Directory Creation", "Directory: " + strDirectoy
+ " created");
else
Log.e("Directory Creation", "Error in Create Directory");
}
Log.i("Imagename : ", imgpath);
} catch (Exception e) {
Log.e("fileException", e.getMessage());
e.printStackTrace();
}
return imgpath;
}
这篇关于运行我自己的相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!