本文介绍了如何使用Camera API来拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用照相机API来捕获照片并保存在相机文件夹或库。
请帮我带一些样本code。

I want to know how to capture photo using Camera API and save in camera folder or in gallery.Please help me with some sample code.

谢谢
Monali

Thanks Monali

推荐答案

试试这个了..
在你的onCreate添加此()
串IMG = getImageName();
现在所说的下面方法在你的onCreate()和应该做的伎俩。

Try this out..Add this in your onCreate(),String img = getImageName();Now Call the below method in your onCreate() and should do the trick.

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 = "";
    try {
        imgname = String.format("%d.png", 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 Created", "Directory: " + strDirectoy
                        + " created");
            else

                Log.e("Directory Creation","Directory Creation failed");
        }



    } catch (Exception e) {

        e.printStackTrace();
    }

    return imgpath;
}

这篇关于如何使用Camera API来拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 14:49