在hololens App中将图像保存到Photos文件夹 [英] Saving an Image to Photos Folder In hololens App

查看:389
本文介绍了在hololens App中将图像保存到Photos文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Hololens应用程序中捕获照片.它似乎正在工作,但是将图像保存到我无法访问或查看的晦涩地方.我想将其保存到我的图片库在此描述想.或者我应该将图像保存在什么地方,以便可以在Hololens的照片中看到它.

I'm attempting to capture a photo inside my hololens app. It seems to be working but saving the image to an obscure place that I cant access or view. I want to save it to my pictures library Described here I think. Or where should i save the image so I can see it in my photos on the hololens.

filePath = C:/Data/Users/JanikJoe/AppData/Local/Packages/HoloToolkit-Unity_pzq3xp76mxafg/LocalState \ CapturedImage10.02831_n.jpg

filePath = C:/Data/Users/JanikJoe/AppData/Local/Packages/HoloToolkit-Unity_pzq3xp76mxafg/LocalState\CapturedImage10.02831_n.jpg

filePath2 = C:/Data/Users/DefaultAccount/AppData/Local/DevelopmentFiles/HoloToolkit-UnityVS.Debug_x86.janik/Data \ CapturedImage10.02831_n.jpg

filePath2 = C:/Data/Users/DefaultAccount/AppData/Local/DevelopmentFiles/HoloToolkit-UnityVS.Debug_x86.janik/Data\CapturedImage10.02831_n.jpg

using UnityEngine;
using UnityEngine.VR.WSA.WebCam;
using System.Linq;

public class PhotoCaptureFVTC : MonoBehaviour {

UnityEngine.VR.WSA.WebCam.PhotoCapture photoCaptureObject = null;
// Use this for initialization
void Start()
{
    Debug.Log("snap pic taken");
    PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
}

public void OnPhotoCaptureCreated(PhotoCapture captureObject)
{
    photoCaptureObject = captureObject;

    //Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
    Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

    CameraParameters c = new CameraParameters();
    c.hologramOpacity = 0.0f;
    c.cameraResolutionWidth = cameraResolution.width;
    c.cameraResolutionHeight = cameraResolution.height;
    c.pixelFormat = CapturePixelFormat.BGRA32;

    captureObject.StartPhotoModeAsync(c, false, OnPhotoModeStarted);
}
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
    photoCaptureObject.Dispose();
    photoCaptureObject = null;
}

private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
{
    if (result.success)
    {
        string filename = string.Format(@"CapturedImage{0}_n.jpg", Time.time);
        string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename);
        string filePath2 = System.IO.Path.Combine(Application.dataPath, filename);

        photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
        Debug.LogError("Saved That Image Somewhere" +"FileName: ="+ filename + " FilePath: = " + filePath + " FilePath2: = " + filePath2);
    }
    else
    {
        Debug.LogError("Unable to start photo mode!");
    }
}
void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result)
{
    if (result.success)
    {
        Debug.Log("Saved Photo to disk!");
        photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
    }
    else
    {
        Debug.Log("Failed to save Photo to disk");
    }
}


}

推荐答案

似乎无法直接保存在相机胶卷文件夹中,并且HoloLens上没有图片库.

It seems to be that it is not possible to save directly in the camera roll folder and there is no picture library on the HoloLens.

此处存在相同的问题: https://forums.hololens.com/discussion/1458/capturing-photo-in-unity-and-saving-to-disk

There is the same question here: https://forums.hololens.com/discussion/1458/capturing-photo-in-unity-and-saving-to-disk

我尝试了解决方法,并且效果很好.只需将保存的图像移至相机胶卷文件夹即可.

I tried the workaround and it works fine. Just move the saved image to the camera roll folder.

#if !UNITY_EDITOR && UNITY_WINRT_10_0
        var cameraRollFolder = Windows.Storage.KnownFolders.CameraRoll.Path;            
        File.Move(_filePath, Path.Combine(cameraRollFolder, _filename));
#endif

这篇关于在hololens App中将图像保存到Photos文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆