运行我自己的相机

发布于 2024-11-04 09:43:17 字数 459 浏览 0 评论 0原文

我是 Java 和 Android 的初学者,在启动相机时遇到问题。准确地说,我需要一个在我控制之下的小型相机预览。 (我想在中间放一个视线)。我尝试将其粘贴到我的项目中: http://developer.android .com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html 但是,在我天真的“修复”之后,在开始任何操作之前,程序崩溃了,有很多错误。 我尝试用google搜索了很长一段时间,但没有成功。 有人拥有可以毫无问题地工作的东西吗?一个项目就好了:)

提前致谢 再见

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-11-11 09:43:17

在您的 onCreate 方法中,提供以下几行,

String  imgName = getImageName();

    startCamera(imgName);

并在您的 onCreate 下方提供这些方法。你的相机已经准备好了。

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

in your onCreate method, provide the below lines,

String  imgName = getImageName();

    startCamera(imgName);

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文