问题描述
根据这篇文章中,我试图做捕捉摄像头的Android模拟器的照片。我跟着指示按他们说。但我没有得到积极的结果。
Based on this article, I'm trying do capture the photo from camera on Android Emulator. I followed the instructions as per they said. But I didn't get the positive result.
我发现了播放
是空
,我在运行时的 WebcamBroadcaster.java
(Java应用程序)。
I'm getting the Player
is null
, while I'm running the WebcamBroadcaster.java
(Java Application).
时之前,任何人做到这一点?如果是的话,让我怎么办。
Is anyone achieve this before? If yes, Just let me how to do.
或
是否有任何其他选项,以捕捉摄像头的Android模拟器?
Is there any other option to capture the photo from camera on Android Emulator?
推荐答案
在 Android模拟器2.1我的code正在拍摄图片,但不工作在其他版本的Android
In Android emulator 2.1 my code is working to capture image but not working in others version of android
要启动相机捕捉您可以通过以下意图过滤器启动相机拍摄
To start camera for capture you can start camera for capture using below intent filter
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_RESULT);
拍摄,所以你需要得到活动的结果,你会得到的图像作为位图后
After capturing you will get the image as bitmap so you need to get activity result
if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {
Bundle extras = data.getExtras();
if(extras.containsKey("data")) {
Bitmap bmp = (Bitmap) extras.get("data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] image = baos.toByteArray();
if(image != null) {
//User this byte array in your application
}
}else {
Toast.makeText(getBaseContext(), "Fail to capture Image", Toast.LENGTH_LONG).show();
}
}
编辑:
现在几乎在所有的仿真器这code正常工作。
Now almost in all the emulators this code is working.
这篇关于如何捕捉摄像头的Android模拟器的照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!