嗨,我正在开发自定义视频应用程序.我能够获得currentCameraId 通过
currentCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
Run Code Online (Sandbox Code Playgroud)
我有两个问题要问:
1)如何只用前置摄像头检测Android设备.
因为在Micromax标签中只有前置摄像头的平板电脑上,currentCameraId为0.
2)如何检查相机闪光灯的可用性,因为下面的代码在某些手机上不起作用
flash = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Run Code Online (Sandbox Code Playgroud)
请帮忙.
谢谢!
flash android android-package-managers android-camera front-camera
嗨,我正在开发 android 应用程序,我正在尝试使用设备摄像头捕获图像并将其保存到特定位置。我用以下方式尝试过:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("inside on create ", "inside on create ");
capturePhotoForRecordUpload();
}
public void capturePhotoForRecordUpload() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File storageDir = new File(Environment.getExternalStorageDirectory().getPath() + "/MyApp");
if(!storageDir.exists())
storageDir.mkdirs();
if(!storageDir.exists())
storageDir.mkdir();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath() + "/MyApp"+"/sample.jpg")));
startActivityForResult(takePictureIntent, 7);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
}
} …Run Code Online (Sandbox Code Playgroud) 我查看了人们提出的其他问题,但我不确定解决此问题的最佳方法是什么。通过 Android 的指南实现相机后,我拥有的相机预览被锁定为横向。我想知道如何调整相机方向以反映手机的方向。
我试过这个
camera.setDisplayOrientation(90);
Run Code Online (Sandbox Code Playgroud)
并且将相机锁定为纵向模式,因此我需要另一种解决方案(最好是适用于大多数设备的解决方案)。
另外,我怎样才能使保存的图像以与预览相同的方式显示?现在,如果我使用上面的那行代码使预览转到纵向,则保存的图像仍会旋转为横向。
我正在尝试使用 CameraX Api 实现 TapToFocus 功能。我已经成功实现了它,但不知道如何在描述用户按下的位置的预览上画一个圆圈。
我有以下简单代码可以拍摄一张照片并返回到呼叫者活动:
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uriSavedImage = Uri.fromFile(new File(Environment
.getExternalStorageDirectory()
+ directory_path
+ "/"
+ Calendar.getInstance().get(Calendar.MILLISECOND)
+ ".jpg"));
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera_intent, 1);
MainActivity.this.startActivityForResult(camera_intent, 0);
Run Code Online (Sandbox Code Playgroud)
但是,只有两张照片后,相机意图才会关闭。因此,在我拍摄一张照片后,相机意图仍然有效。在我拍摄另一张照片之后,直到现在,相机意图才被关闭onActivityResult并被调用。
怎么了?
编辑:我尝试将日志消息打印到onActivityResult中,并且我注意到onActivityResult被调用了两次,但是仅在第二张图片之后(并且在相机意图关闭之后)
使用Android移动相机
想要对Android移动相机实现运动模糊效果.
这是在iOS中使用过滤器GPUImageLowPassFilter实现的.我想在android中替代它.
我正在尝试从我的应用程序中制作图片。我可以启动相机并拍照,但是完成拍照后我的应用程序崩溃。我在屏幕上看到我的Galery已停止,这是我的日志中的错误:
我试图找到一些东西,但是对我有帮助。
提前致谢
FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=file:///data/data/com.android.gallery3d/files/crop-temp (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
at android.app.Activity.startActivityForResult(Activity.java:3388)
at android.app.Activity.startActivityForResult(Activity.java:3349)
at com.android.camera.actor.PhotoActor.doAttach(PhotoActor.java:1125)
at com.android.camera.actor.PhotoActor.access$500(PhotoActor.java:62)
at com.android.camera.actor.PhotoActor$2.onClick(PhotoActor.java:210)
at android.view.View.performClick(View.java:4209)
at android.view.View$PerformClick.run(View.java:17431)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@Override
public void onButton1Click(int ref) {
try {
currentRef = ref;
Intent mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + …Run Code Online (Sandbox Code Playgroud) 我正在尝试确定闪光灯是打开还是关闭,这样只需一个按钮我就可以打开和关闭闪光灯.这是我的代码:
Camera cam = getCameraInstance(); //A method that opens the cam
Camera.Parameters parameters = cam.getParameters();
System.out.println("Current flash mode " + parameters.getFlashMode());
System.out.println("flash mode off equals to : " + Camera.Parameters.FLASH_MODE_OFF);
System.out.println(parameters.getFlashMode() == Camera.Parameters.FLASH_MODE_OFF);
Run Code Online (Sandbox Code Playgroud)
前两个系统的输出是off.当然我假设因为它们都返回一个off字符串,将==操作符放在它们之间会返回true(因此允许我检查闪存是否打开)但它返回false.知道为什么吗?
我的目标是api 16并在Marshmallow设备上进行测试
阅读本文档https://developer.android.com/training/camera/photobasics后,我想拍摄一张照片并将照片的 uri 存储到给定的变量中。问题是我使用takePictureIntent.putExtra(Constants.INTENT_EXTRA_VARNAME, variable)and将变量名称和 uri 存储到意图中takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI),但在 onActivityResult 中意图数据为空,并且存储的变量和 uri 都不为空。我需要知道 uri 和变量。我究竟做错了什么?
我需要将信息作为意图数据传递,因为触发显示相机的操作的类与活动类不同。
带有动作的类:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(Constants.INTENT_EXTRA_VARNAME, variable);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(SectionManager.getInstance().getCurrentActivity().getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile …Run Code Online (Sandbox Code Playgroud) camera android android-intent android-camera onactivityresult