level 1
时间恶劣
楼主
按照网上Hololens的例子在VS上做了个C
#的工程,但是由于之前没用过C#
也没用过Hololens,按网上的例子获取了一个SoftwareBitmap类型的图像以后找不到保存到设备的方法,因为运行是在hololens上,目前想要一边运行拍照程序一边讲获取的图像保存到本地。
看网上对于这种类型的数据保存是使用的Storagefile的方式:
public async Task WriteToFileAsync(StorageFolder folder, SoftwareBitmap sb, string fileName)
{
if (sb != null)
{
// save image file to cache
// StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFolder applicationFolder = await folder.CreateFolderAsync("Pic", CreationCollisionOption.ReplaceExisting);
StorageFile file = await folder.CreateFileAsync("hololes.jpg", CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.SetSoftwareBitmap(sb);
await encoder.FlushAsync();
}
}
return;
}
使用这种方式进行保存的话,感觉运行时速度明显变慢了,感觉在获取图像后是在做保存处理,但是找了一圈找不到对应保存的文件。
而且上面这种保存的方法我也是第一次使用,看到网上文档里说是会保存到C盘的路径下,但是还是不懂 ApplicationData.Current.LocalFolder所指的路径位置……
因此想请教一下在Windows系统下,对于SoftwareBitmap的保存有没有更方便的方案。
2018年08月08日 07点08分
1
#的工程,但是由于之前没用过C#
也没用过Hololens,按网上的例子获取了一个SoftwareBitmap类型的图像以后找不到保存到设备的方法,因为运行是在hololens上,目前想要一边运行拍照程序一边讲获取的图像保存到本地。
看网上对于这种类型的数据保存是使用的Storagefile的方式:
public async Task WriteToFileAsync(StorageFolder folder, SoftwareBitmap sb, string fileName)
{
if (sb != null)
{
// save image file to cache
// StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFolder applicationFolder = await folder.CreateFolderAsync("Pic", CreationCollisionOption.ReplaceExisting);
StorageFile file = await folder.CreateFileAsync("hololes.jpg", CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.SetSoftwareBitmap(sb);
await encoder.FlushAsync();
}
}
return;
}
使用这种方式进行保存的话,感觉运行时速度明显变慢了,感觉在获取图像后是在做保存处理,但是找了一圈找不到对应保存的文件。
而且上面这种保存的方法我也是第一次使用,看到网上文档里说是会保存到C盘的路径下,但是还是不懂 ApplicationData.Current.LocalFolder所指的路径位置……
因此想请教一下在Windows系统下,对于SoftwareBitmap的保存有没有更方便的方案。