如何在Android模拟器上捕捉相机中的照片?

bha*_*ath 5 android android-emulator android-camera

基于这篇文章,我试图在Android模拟器上捕捉相机中的照片.我按照说明按照说明操作.但我没有得到积极的结果.

我得到的Player就是null,当我运行WebcamBroadcaster.java(Java应用程序).

以前有人能做到这一点吗?如果有,请让我该怎么做.

要么

还有其他选项可以从Android模拟器上的摄像头捕获照片吗?

Dha*_*dra 9

Android模拟器2.1中,我的代码正在捕获图像 但不能在其他版本的android中工作

要启动摄像头进行捕获,您可以使用下方过滤器启动摄像头进行捕获

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_RESULT);
Run Code Online (Sandbox Code Playgroud)

捕获后,您将获得图像作为位图,因此您需要获取活动结果

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

现在,几乎在所有模拟器中,此代码都正常工作.