如何在没有意图的情况下从相机拍摄照片 [英] How to capture a photo from the camera without intent
问题描述
我希望我的应用能够在不使用其他应用的情况下拍摄照片.我使用的代码:
I want my app to be able to capture photos without using another application. The code i used :
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photo = null;
try
{
photo = this.createTemporaryFile("picture", ".jpg");
photo.delete();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
mImageUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
但此代码使用手机的主摄像头应用.谁能给我一些代码?
But this code uses the phone's main camera app. Can anyone give me some code ?
推荐答案
直接使用 Camera
类拍照非常复杂.
Taking a picture directly using the Camera
class is insanely complicated to get right.
我正在开发一个简化此操作的库,您只需添加一个 CameraFragment
到您的应用程序的基本预览 UI,并在其上调用 takePicture()
以拍摄照片,并通过各种方式配置行为(例如,保存图片的位置).但是,这个库仍在进行中.
I am working on a library to simplify this, where you just add a CameraFragment
to your app for the basic preview UI, and call takePicture()
on it to take a picture, with various ways to configure the behavior (e.g., where the pictures get saved). However, this library is still a work in progress.
谁能给我一些代码?
某些代码"将长达数千行(对于完整的实现,包括处理各种特定于设备的怪事).
"Some code" is going to be thousands of lines long (for a complete implementation, including dealing with various device-specific oddities).
欢迎您阅读有关该主题的 Android 开发人员文档.
这篇关于如何在没有意图的情况下从相机拍摄照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!