Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture the photo from camera on Android Emulator?

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.

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.

Or

Is there any other option to capture the photo from camera on Android Emulator?

like image 976
bharath Avatar asked Dec 14 '11 13:12

bharath


2 Answers

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();
    }
}

Edit:

Now almost in all the emulators this code is working.

like image 106
Dharmendra Avatar answered Oct 12 '22 19:10

Dharmendra


As hes mentioning in his article he wrote this code in haste and it may be kinda buggy therefore. It's not said to work everywhere at all.

Im assuming your using exactly this code to run this thing:

CameraSource cs = new SocketCamera("192.168.0.100", 9889, 320, 240, true);
if (!cs.open()) { /* deal with failure to obtain camera */ }
while(/*some condition*/) {
  cs.capture(canvas) //capture the frame onto the canvas
}
cs.close();

What is, by the way, the main purpose of doing such things? All camera aligned things should tested exhaustively on a real device, because it can cause loads of problems which does not occur at an emulator. The camera implementation of the camera is for debug/testing purposes, only!

I would strongly recommend to not spend to much time into getting this running, it won't lead you very far. It still has not been tested on a real device, though, which would be the very most important.

I hope I didn't disappoint you too much with this answer :/

like image 25
poitroae Avatar answered Oct 12 '22 17:10

poitroae