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
void onPhotoCaptured(List<byte> image, int width, int height)
{
Globals.LastTexture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);
Globals.LastTexture2D.LoadImage(image.ToArray());
ImagePlain.GetComponent<MeshRenderer>().material.mainTexture = Globals.LastTexture2D;
#if WINDOWS_UWP
//string name = Windows.Storage.KnownFolders.CameraRoll + "\\SavedScreen" + DateTime.Now.Ticks.ToString() + ".png";
//Debug.LogWarning("Saving to: " + name);
//File.WriteAllBytes(name, image.ToArray());
string name = Windows.Storage.KnownFolders.PicturesLibrary.Path + "\\SavedScreen" + DateTime.Now.Ticks.ToString() + ".png";
Debug.LogWarning("Saving to: " + name);
File.WriteAllBytes(name, image.ToArray());
#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?
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.
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 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…
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!
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.