How do I release the Camera when using MediaStore.ActionImageCapture to take pictures?

AlejandroRmzAlejandroRmz USUniversity ✭✭

I have an Android app that uses the camera to take a picture (wrote the code using the sample linked below), but whenever I quit the app, the Camera is not released properly, so subsequent attempts to immediately open the app after closing it fail (the app crashes). If I wait about 10 seconds then the Camera is released and I can reopen the app.

I tried Camera.release() but that method is not recognized. Any idea?

https://developer.xamarin.com/recipes/android/other_ux/camera_intent/take_a_picture_and_save_using_camera_app/

Tagged:

Answers

  • AlejandroRmzAlejandroRmz USUniversity ✭✭

    In case anyone runs into this dilemma, the problem wasn't about releasing the camera, but rather about not releasing the memory used by the bitmap object used to save the file.

    All I did to fix this issue was to add this code:

    // **bitmap** is a public static field used to hold the image taken by the camera (read from the media storage)
    // **_imageView** displays the taken image to the user on another view
    
    protected override void OnDestroy()
    {
        base.OnDestroy();
        bitmap = null;
        _imageView.SetImageBitmap(null);
    }
    
  • rakeshraghavanrakeshraghavan INMember ✭✭

    I released bitmap values. But still i am getting black screen in android as well as ios.

Sign In or Register to comment.