Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Cannot save or display photo on hololens created by onPhotoCaptured

Discussion in 'VR' started by LR-Developer, Jun 9, 2017.

  1. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,

    I am using a QR Code scanner. It Needs Input by a Byte Array, So I am using

    photoInput.CapturePhotoAsync(onPhotoCaptured);

    to create my snapshot photo.

    It works sometimes but not always.

    So I want to check my photo if it is too wiggly, blurred, small, large or something.

    Now I have huge unexpected Problems checking my photo!

    I try two ways:

    - Displaying it on a mesh (plain) in the renderer material.
    - Saving it to File

    Code (CSharp):
    1.  
    2. void onPhotoCaptured(List<byte> image, int width, int height)
    3.     {
    4.         Globals.LastTexture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);
    5.         Globals.LastTexture2D.LoadImage(image.ToArray());
    6.         ImagePlain.GetComponent<MeshRenderer>().material.mainTexture = Globals.LastTexture2D;
    7. #if WINDOWS_UWP
    8.         //string name = Windows.Storage.KnownFolders.CameraRoll + "\\SavedScreen" + DateTime.Now.Ticks.ToString() + ".png";
    9.         //Debug.LogWarning("Saving to: " + name);
    10.         //File.WriteAllBytes(name, image.ToArray());
    11.         string name = Windows.Storage.KnownFolders.PicturesLibrary.Path + "\\SavedScreen" + DateTime.Now.Ticks.ToString() + ".png";
    12.         Debug.LogWarning("Saving to: " + name);
    13.         File.WriteAllBytes(name, image.ToArray());
    14. #endif
    Something strange happens when I Display it. The 3D Plain Shows a red question mark on White ground now. Why is that? Any hint please?

    And I cannot get it to save in the hololens Picture Gallery. A storage file has no WriteAllBytes method, and I do not know and find a way to save it to the Picture Folder with the System.IO.file...

    It would be great if I could get one of those two ways working, any idea what I am doing wrong?

    Thanks a lot!
     
    Last edited: Jun 9, 2017
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    First thing I see jump out is the string for saving the screen shot, does Windows.Storage.KnownFolders.PicturesLibrary.Path work for you? Also, I don't see anywhere were you grab the texture from the photocapture object.

    example:
    photoCaptureFrame.UploadImageDataToTexture(m_TargetTexture);
     
  3. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,

    like in line 5 of my Code, I try to fill a global Texture2D like this or that:

    Globals.LastTexture2D.LoadImage(image.ToArray());
    Globals.LastTexture2D.LoadRawTextureData(image.ToArray());

    I thought that should work. I do not see a UploadImageDataToTexture in my context. I am using this result void because the Byte Array works fine with my Decoder, I only would like to have an additional test Image I can see:

    void onPhotoCaptured(List<byte> image, int width, int height)

    And in Line 11 I am already using like you suggest

    string name = Windows.Storage.KnownFolders.PicturesLibrary.Path + "\\SavedScreen" + DateTime.Now.Ticks.ToString() + ".png";

    but it does just do nothing. I made a try .. catch around it now and debugged it and it is empty when I use it this way. I thought I could use it like a string. I try to find out how it works. If it only Returns me a storgage file I do not know how to write a storage file this way with the Byte list or Array...

    Thanks for helping!
     
  4. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    PS: I just found my Byte Array method (it is from a sample I found) is not from Unity itself, it is some callback got from the onCapturedPhotoToMemory where I have a frame from the photocapture object, just like you said, sorry. I will try to work with this one, thanks!
     
  5. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    I was asking if the path Windows.Storage.KnownFolders.PicturesLibrary.Path works for you, as I haven't tried it and was curious about API.
     
  6. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    It is empty, if you use it like a string.

    You need to get it in an async manner and can use it with a StorageFile instead of an IO.File it seems. but this StorageFile does not Support writing Byte Arrays to disk etc, it seems to be very limited. I am not sure about how to use it, but not like a string for a path / Folder.

    See here:
    https://docs.microsoft.com/en-us/uwp/api/windows.storage.knownfolders
     
  7. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Sweet, thank you for the info