运行我自己的相机自己的、相机

由网友(冷眼看世界)分享简介:我是一个初学者到Java和Android,而我有推出相机有问题。 precisely我需要一个小型相机preVIEW这将是我的控制之下。 (我希望把眼前的景象在它的中间)。我想这个贴到我的项目:http://developer.android.com/resources/samples/ApiDemos/src/com...

我是一个初学者到Java和Android,而我有推出相机有问题。 precisely我需要一个小型相机preVIEW这将是我的控制之下。 (我希望把眼前的景象在它的中间)。我想这个贴到我的项目: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.html But 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 advance Bye

推荐答案

在您的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;
}
阅读全文

相关推荐

最新文章