Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Native Camera for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, May 2, 2018.

  1. lukasz_klapiszewski

    lukasz_klapiszewski

    Joined:
    Mar 8, 2019
    Posts:
    3
    Hi

    I'm using Native Camera plugin. Everything is ok when I record a video. But when I'm takeing picture there is popup information "No memory space". Max image size is set to 512. After takeing photo path to the image is null. I have privileges to camera and storage. What can cause the problem?

    My device is HMT1 (RealWear)
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Is your internal storage nearly full? Maybe the camera app internally decides to save the recorded video to SD card but save the photo to internal storage and can't find enough space in internal storage.
     
  3. lukasz_klapiszewski

    lukasz_klapiszewski

    Joined:
    Mar 8, 2019
    Posts:
    3
    I have 10,1GB free and no SD card installed.
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    I wish I could help but NativeCamera simply starts the native camera app and leaves all the implementation details to that app. The "No memory space" error isn't directly generated by NativeCamera and I'm not sure how this issue can be resolved.

    P.S. This is the first time I'm encountering this issue in my plugins.
     
  5. lukasz_klapiszewski

    lukasz_klapiszewski

    Joined:
    Mar 8, 2019
    Posts:
    3
    I tried to make a photo outside application and everything is ok. I've also tried to make photo from application (using NativeCamera) on my android phone and everything is ok. Problem exists only on HMT1 (RealWear)
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    I understand but even googling "No memory space" doesn't really provide any useful info to me. I don't know where to look to resolve this issue with just the information I have.
     
  7. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour
    {
    public void Gallerybutton;


    public void Camerabutton;


    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetMouseButtonDown(0))
    {
    // Don't attempt to use the camera if it is already open
    if (NativeCamera.IsCameraBusy())
    return;

    if (Input.mousePosition.x < Screen.width / 2)
    {
    // Take a picture with the camera
    // If the captured image's width and/or height is greater than 512px, down-scale it
    TakePicture(512);
    }
    else
    {
    // Record a video with the camera
    RecordVideo();
    }
    }
    }

    private void TakePicture(int maxSize)
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture((path) =>
    {
    Debug.Log("Image path: " + path);
    if (path != null)
    {
    // Create a Texture2D from the captured image
    Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize);
    if (texture == null)
    {
    Debug.Log("Couldn't load texture from " + path);
    return;
    }

    // Assign texture to a temporary quad and destroy it after 5 seconds
    GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
    quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
    quad.transform.forward = Camera.main.transform.forward;
    quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);

    Material material = quad.GetComponent<Renderer>().material;
    if (!material.shader.isSupported) // happens when Standard shader is not included in the build
    material.shader = Shader.Find("Legacy Shaders/Diffuse");

    material.mainTexture = texture;

    Destroy(quad, 5f);

    // If a procedural texture is not destroyed manually,
    // it will only be freed after a scene change
    Destroy(texture, 5f);
    }
    }, maxSize);

    Debug.Log("Permission result: " + permission);
    }

    private void RecordVideo()
    {
    NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
    {
    Debug.Log("Video path: " + path);
    if (path != null)
    {
    // Play the recorded video
    Handheld.PlayFullScreenMovie("file://" + path);
    }
    });

    Debug.Log("Permission result: " + permission);
    }

    void Update()
    {
    if (Input.GetMouseButtonDown(0))
    {
    // Don't attempt to use the camera if it is already open
    if (NativeCamera.IsCameraBusy())
    return;

    if (Input.mousePosition.x < Screen.width / 2)
    {
    // Take a picture with the camera
    // If the captured image's width and/or height is greater than 512px, down-scale it
    TakePicture(512);
    }
    else
    {
    // Record a video with the camera
    RecordVideo();
    }
    }
    }

    private void TakePicture(int maxSize)
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture((path) =>
    {
    Debug.Log("Image path: " + path);
    if (path != null)
    {
    // Create a Texture2D from the captured image
    Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize);
    if (texture == null)
    {
    Debug.Log("Couldn't load texture from " + path);
    return;
    }

    // Assign texture to a temporary quad and destroy it after 5 seconds
    GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
    quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
    quad.transform.forward = Camera.main.transform.forward;
    quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);

    Material material = quad.GetComponent<Renderer>().material;
    if (!material.shader.isSupported) // happens when Standard shader is not included in the build
    material.shader = Shader.Find("Legacy Shaders/Diffuse");

    material.mainTexture = texture;

    Destroy(quad, 5f);

    // If a procedural texture is not destroyed manually,
    // it will only be freed after a scene change
    Destroy(texture, 5f);
    }
    }, maxSize);

    Debug.Log("Permission result: " + permission);
    }

    private void RecordVideo()
    {
    NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
    {
    Debug.Log("Video path: " + path);
    if (path != null)
    {
    // Play the recorded video
    Handheld.PlayFullScreenMovie("file://" + path);
    }
    });

    Debug.Log("Permission result: " + permission);
    }
    }
     
  8. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
    I have the following errors, can you help with this
     

    Attached Files:

  9. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
    There is an error for the NativeCamera, TakePicture, RecordVideo,
     

    Attached Files:

  10. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    In your script, you have 2 Updates, 2 TakePictures and 2 RecordVideos. Probably a copy&paste mistake. Removing one copy of each function from the script should resolve the issue.
     
  12. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    I can't get this plugin to work :(
    I have an app that is able to pick the image from android, upload it to FB and created separate scene for your plugin.
    Basically only button back to main scene and button "make photo" with function from your github attached.
    I click the button and nothing happens. Will greatly appreciate any help.

    This is my code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;

    public class NativeCameraMakePhotoScript : MonoBehaviour
    {

    [SerializeField]
    Button makePhotoButton;

    [SerializeField]
    Button backButton;


    void Start()
    {
    makePhotoButton.onClick.AddListener(delegate{TakePicture(1024);});
    backButton.onClick.AddListener(BackToMainScene);
    }

    void Update()
    {
    if( NativeCamera.IsCameraBusy() )
    return;
    }

    private void TakePicture( int maxSize )
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture( ( path ) =>
    {
    Debug.Log( "Image path: " + path );
    if( path != null )
    {
    // Create a Texture2D from the captured image
    Texture2D texture = NativeCamera.LoadImageAtPath( path, maxSize );
    if( texture == null )
    {
    Debug.Log( "Couldn't load texture from " + path );
    return;
    }

    // Assign texture to a temporary quad and destroy it after 5 seconds
    GameObject quad = GameObject.CreatePrimitive( PrimitiveType.Quad );
    quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
    quad.transform.forward = Camera.main.transform.forward;
    quad.transform.localScale = new Vector3( 1f, texture.height / (float) texture.width, 1f );
    Material material = quad.GetComponent<Renderer>().material;
    if( !material.shader.isSupported ) // happens when Standard shader is not included in the build
    material.shader = Shader.Find( "Legacy Shaders/Diffuse" );

    material.mainTexture = texture;
    Destroy( quad, 5f );

    // If a procedural texture is not destroyed manually,
    // it will only be freed after a scene change
    Destroy( texture, 5f );
    }
    }, maxSize );

    Debug.Log( "Permission result: " + permission );
    }


    public void BackToMainScene(){
    SceneManager.LoadSceneAsync("SampleScene");
    }

    }
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Please make sure that you've completed these steps:

    - set Write Permission to External (SDCard) in Player Settings
    - (Android) add the provider to your AndroidManifest.xml: https://github.com/yasirkula/UnityNativeCamera/#android-setup
    - if you are using ProGuard, make sure to make an exception for the plugin's classes: https://github.com/yasirkula/UnityNativeCamera/#faq

    I'd also recommend you to check logcat/Xcode console for any meaningful error messages.

    P.S. You don't need the Update function in your script.
     
  14. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    First of all, thank you for the replay. I did all those steps.
    Maybe I will just write what I did step by step, maybe I did a mistake and its my fault: Created new project.
    Added Android manifest (catalogue Plugins/Android), wrote the code above, changed the write permissions, checked if it works in unity -> I can see the response in the console: it shows me "Path" and "Permission: Granted".
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Are you testing on the Unity Editor or on a device? While testing on an Android device, check out the Logcat logs, as well. Some important logs may show up in Logcat only.
     
  16. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
    I successfuly used nativecamera to take a photo and render it on a raw image and now it remains on the screen, but now I want to move the rendered image to another scene. How can I do that?
     
  17. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
    I happen to have an avatar placed into the scene from taking a picture with a camera, on the same scene I can select the player I want. Once I click the confirm button the new player gets loaded into the next scene successfully, but I am unable to make the avatar move into the new scene as well. How do I make the avatar move alongside the selected player into the next scene after clicking the confirm button? I already modified my camera script to store the avatar image permanently on the screen, aside from this I am unable to move the image into the scene with the selected player. I am pretty new to unity so I am kind of lost

    My script for moving the character below

    using System.Collections;
    using UnityEngine.SceneManagement;

    public class CharacterSelection : MonoBehaviour
    {
    private int index;
    private GameObject[] characterList;

    private void Start()
    {
    index = PlayerPrefs.GetInt("ChracterSelected");
    characterList = new GameObject[transform.childCount];

    //fill the array with our models
    for(int i = 0; i < transform.childCount; i++)

    characterList = transform.GetChild(i).gameObject;
    // we toggle off their renderer
    foreach (GameObject go in characterList)
    go.SetActive(false);

    // we toggle on the selected character
    if (characterList[index])
    characterList[index].SetActive(true);


    }


    MY SCRIPT FOR storing the photo permanently on the screen which works

    using UnityEngine.UI;

    public class takePhoto : MonoBehaviour

    {
    public RawImage photoTaken;

    public void TakePictureButton()
    {
    TakePicture(512);
    }

    private void TakePicture(int maxSize)
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture((path) =>
    {
    Debug.Log("Image path: " + path);
    if (path != null)
    {
    // Create a Texture2D from the captured image
    Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize);
    if (texture == null)
    {
    Debug.Log("Couldn't load texture from " + path);
    return;
    }

    photoTaken.texture = texture;
    photoTaken.gameObject.SetActive(true);



    }
    }, maxSize);

    Debug.Log("Permission result: " + permission);
    }

    }




    public void ToggleLeft()
    {
    // Toggle of the current model
    characterList[index].SetActive(false);
    index--; //index -=1; index=index -1;
    if (index < 0)
    index = characterList.Length - 1;

    // Toggle on the new model
    characterList[index].SetActive(true);
    }

    public void ToggleRight()
    {
    // Toggle of the current model
    characterList[index].SetActive(false);

    index++; //index -=1; index=index -1;
    if (index == characterList.Length)
    index = 0;

    // Toggle on the new model
    characterList[index].SetActive(true);

    }

    public void confirm()
    {
    PlayerPrefs.SetInt("ChracterSelected", index);
    SceneManager.LoadScene("RoleOutput");
    }
    }



     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    The easiest solution would be to store the image in a
    public static Texture2D Avatar { get; private set; }
    property inside the takePhoto class. After adding this property to the class, you can simply say
    Avatar = texture;
    before calling
    photoTaken.texture = texture;
    . Then, from any scene, you can access this image via
    photoTaken.Avatar
    and assign it to a RawImage in that particular scene.
     
  19. eijie

    eijie

    Joined:
    Dec 16, 2015
    Posts:
    3
    upload_2019-8-6_15-46-30.png


    i change in androidmanifest.xml

    but my app cant installed

    help
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Don't change
    android:name
    , change only
    android:authorities
    .
     
  21. eijie

    eijie

    Joined:
    Dec 16, 2015
    Posts:
    3
    thanks its work

    can this plugin image from folder path ??
    like browse file
     
  22. Seve2

    Seve2

    Joined:
    May 13, 2019
    Posts:
    17
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
  24. fraeri

    fraeri

    Joined:
    Nov 8, 2018
    Posts:
    64
    Hi Yasirkula,
    thanks for making this great asset for free! I was able to make it work within minutes. One Question that came already to my mind is the language the nativeCamera is using. When the CameraView is open everything is in English. "Retake", "Use Photo" .. Is it possible to use the device language for these?

    Also: is it possible to make more than one picture at import them at once? I'm thinking of the behavior of whatsapp when sending multiple pictures.


    Thanks & Regards,
    Eric
     
    Last edited: Aug 12, 2019
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    The native camera app shows those labels, so I'm guessing that they're affected by the device's language settings. If not, I don't think I've any control over them since googling
    ACTION_IMAGE_CAPTURE "localization"
    yields no relevant results.

    You can call NativeCamera.TakePicture again in the CameraCallback, so the camera will open again right after an image is captured. This might not work on iOS at the moment but I'll fix it soon.
     
  26. NDAP

    NDAP

    Joined:
    Mar 23, 2017
    Posts:
    2
    hello,
    first of all thank you for making this free, but i'm running into a problem:
    when going into the camera and taking a picture, or when going into camera and pressing back button, the app restarts
    (if it helps) i used native gallery asset to load an image from gallery and it doesn't restart
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Is it happening on a very old device? Opening the camera increases the memory usage and if OS runs out of memory, it starts killing background activities, including Unity. I've seen this behaviour occasionally on Galaxy S3 but never on newer and more powerful devices. I'm afraid it is out of my hands.
     
  28. eldongour

    eldongour

    Joined:
    Dec 9, 2018
    Posts:
    1
    I am having an issue like this too. Do you know why its not capturing image?
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
  30. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Hi, I installed your plugin in a separate project and it worked like a charm (therefor I immediately changed to 5 stars). I think I know why I have a problem in my main project - I'm using also another plugin and I assume their manifests are conflicting? (Don't know much about Android so its my assumption). If you could help me with this I would be extremely grateful. Is it possible to merge both manifests? The second one looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kakeragames.unimgpicker">
    <application>
    </application>
    </manifest>

    EDIT: I created empty project and included both plugins. Worked like a charm. No idea why it doesn't work in my main project. Is it possible that I have a conflict with Firebase or Playfab? Since the firebase files are in the Android catalogue before I put the Android Manifest there, could they create a conflict?
     
    Last edited: Sep 20, 2019
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    If your main project uses ProGuard minification in Player Settings, you should add the following line to the ProGuard filters:
    -keep class com.yasirkula.unity.* { *; }
    . Let me know if your project uses a minification other than None and ProGuard.

    Otherwise, assuming that both projects have Write Permission set to "External (SDCard)" and have the same AndroidManifest.xml files at exactly the same places, this issue shouldn't occur.
     
  32. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    I created empty project and included both plugins (Native Camera and UnimgPicker). Worked like a charm. No idea why it doesn't work in my main project. Is it possible that I have a conflict with Firebase or Playfab? Since the Firebase files are in the Android catalogue before I put the Android Manifest there, could they create a conflict?
    When the Android Manifest file is not there, build and run works perfect. When I put it in the Android catalogue (which already contains Firebase) the app builds successfully, but won't install :( I'm a bit desperate...
     
    Last edited: Sep 20, 2019
  33. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Was able to track the issue:
    After adding your AndroidManifest i get this:
    Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]

    I think it solves it.... I feel stupid now :)
     
    Last edited: Sep 20, 2019
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Try changing the value of your
    android:authorities
    string.
     
  35. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Thank you, already did it, works like a charm :) Anyway, I have last question haha Sorry for bothering you so much :(
    I wanted to ask you about the best way to save the photo. I mean I have the code to save it on Android but it doesn't work in this case.


    private void TakePicture( int maxSize )
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture( ( path ) =>
    {
    Debug.Log( "Image path: " + path );
    if( path != null )
    {
    // Create a Texture2D from the captured image
    cacheTexture = NativeCamera.LoadImageAtPath( path, maxSize );

    if( cacheTexture == null )
    {
    Debug.Log( "Couldn't load texture from " + path );
    return;
    }


    SaveImageToGallery(cacheTexture, "test", "test");

    }
    }, maxSize );

    Debug.Log( "Permission result: " + permission );

    }


    public string SaveImageToGallery(Texture2D texture2D, string title, string description)
    {
    using (var mediaClass = new AndroidJavaClass(MediaStoreImagesMediaClass))
    {
    using (var cr = Activity.Call<AndroidJavaObject>("getContentResolver"))
    {
    var image = Texture2DToAndroidBitmap(texture2D);
    var imageUrl = mediaClass.CallStatic<string>("insertImage", cr, image, title, description);
    return imageUrl;
    }
    }
    }

    public AndroidJavaObject Texture2DToAndroidBitmap(Texture2D texture2D)
    {
    byte[] encoded = texture2D.EncodeToPNG();
    using (var bf = new AndroidJavaClass("android.graphics.BitmapFactory"))
    {
    return bf.CallStatic<AndroidJavaObject>("decodeByteArray", encoded, 0, encoded.Length);
    }
    }
     
  36. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    I also tried doing simply:

    imgBytes = texture.EncodeToPNG();
    var dirPath = Application.persistentDataPath;
    File.WriteAllBytes(dirPath + "Image" + ".png", imgBytes);

    But it saved empty png :(
     
  37. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    I managed to solve it by writing this function (where _imgPath = path). Hope it will help someone in the future :):

    public void QuickSave(){
    if(!String.IsNullOrEmpty(_imgPath)) {
    imgBytes = File.ReadAllBytes(_imgPath);
    cacheTexture = new Texture2D(2, 2);
    cacheTexture.LoadImage(imgBytes);
    SaveImageToGallery(cacheTexture, "testCache", "test");
    }
    }
    Anyway, this solution is pretty simple and clean, but a bit slow :(
     
    yasirkula likes this.
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Or, you can simply copy the image at "path" to wherever you want via File.Copy. Nothing else can beat its speed. And you should use Path.Combine(dirPath, "Image.png") to create paths, otherwise you'll have to handle / and \ characters manually.
     
    piokot likes this.
  39. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Thank you, I will definitely try this!
     
  40. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Works great with Application.persistentpath but I have no idea how to copy it to
    android.provider.MediaStore$Images$Media
     
  41. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Another thing that I can't wrap my mind around is it seems to be impossible to adjust the aspect ratio of the image to the texture.
    Works in every single scenario besides this:

    private void TakePicture( int maxSize )
    {
    NativeCamera.Permission permission = NativeCamera.TakePicture( ( path ) =>
    {
    Debug.Log( "Image path: " + path );

    _imgPath = path;

    if( path != null )
    {
    // Create a Texture2D from the captured image
    Texture2D texture = NativeCamera.LoadImageAtPath( path, maxSize );

    if( cacheTexture == null )
    {
    Debug.Log( "Couldn't load texture from " + path );
    return;
    }


    //Getting the aspect ratio
    float textH = texture.height;
    float textW = texture.width;
    Debug.Log("H: " + textH + " W: " + textW);

    float aspectRation = textH > textW ? textH / textW : textW / textH;

    output.GetComponent<AspectRatioFitter>().aspectRatio = aspectRation;
    output.texture = texture;

    }
    }, maxSize );

    Debug.Log( "Permission result: " + permission );

    }
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    piokot likes this.
  43. piokot

    piokot

    Joined:
    Jul 11, 2018
    Posts:
    13
    Thank you for the response, unfortunately it didn't work either :(
     
  44. SarbaJB

    SarbaJB

    Joined:
    Jul 6, 2017
    Posts:
    2
    Hi! I was testing a little bit with the Quality parameter of the RecordVideo. It doesn't seem to change much, and the size of the video stays pretty much the same. Is this something that the device camera settings can override?
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Some Android camera apps (even built-in camera apps) may not respect the parameters NativeCamera sends to them like quality, video length and etc. It is out of my control, unfortunately. So you shouldn't 100% rely on them.
     
  46. unitystefan

    unitystefan

    Joined:
    Mar 16, 2018
    Posts:
    9
    Hi yasirkula!
    First of, thank you for all of your work not just this one, all are very useful!

    I have few questions regarding NativeCamera:

    - Is there a way to take more than just one photo when Camera app is opened? Because, after one photo is shot, there is "retry" and "ok". It would be great if there is possibility to shot photos as user want, then save them (example, with your NativeGallery to gallery) and when user is done with shooting there is a button to go back to Unity app (I know its impossible to put overlay on Camera app, but back button is enough for now).

    - I tried your example script with your NativeGallery and in Android build (I didn't tried iOS build yet) images are rotated 90 degrees counterclockwise, is there are way to fix it that I missed inside these plug-ins?

    Thank you very much once again!
     
    boyrazemre01 likes this.
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    Hi!

    1. It is not possible, sorry. I have no control over the native camera app, even the screen with the retry and OK buttons is shown by the camera app. I regain control only after the camera is closed entirely. You'll have to call TakePicture continuously inside TakePicture's callback until the path is null (camera is closed with back button).

    2. If you are loading the image via LoadImageAtPath, that is not the expected behaviour. I think it is the first time I'm hearing about this issue on Android, though. Is this behaviour persistent across all your test devices?
     
  48. unitystefan

    unitystefan

    Joined:
    Mar 16, 2018
    Posts:
    9
    Hi yasirkula!

    Thank you for your quick reply.

    1. Oh that's a real bummer. I have to think something out, it wont be user friendly if user have to tap accept for every photo (and user will have to make around 30 photos in my app). Thats a real bummer...

    2. Update for this problem. I tried on another device and it works fine as it should. So, on Xiaomi Mi 9T works fine, on Samsung S8 Plus is were the problem happens. Just so you know, the problem isn't on quad in front of the camera (talking about your example script), it happens when you save it to gallery.
     
  49. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,798
    For 1), you'll have to use a plugin that displays camera feed directly inside Unity and also supports capturing a photo with the camera. For example, this plugin might work for you but I haven't tried it myself, so no guarantees.

    2) There are two SaveImageToGallery overloads: one takes "string path" parameter and the other takes "Texture2D texture" parameter. Can you try using the one you are not currently using and see if it changes anything? And for reference, which Android OS is your S8+ running on?
     
  50. unitystefan

    unitystefan

    Joined:
    Mar 16, 2018
    Posts:
    9
    1. That's exactly what I was thinking, NatCam seems good enough for my purpose and a time cutter, I will give it a try.
    2. I tested it out, with "Texture2D texture" parameter it works as it should on S8+. On both devices is Android 9.

    Thank you for your effort!
     
    yasirkula likes this.