Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从路径wp8获取流_C#_Windows Phone 8_Isolatedstorage_Media Library - Fatal编程技术网

C# 从路径wp8获取流

C# 从路径wp8获取流,c#,windows-phone-8,isolatedstorage,media-library,C#,Windows Phone 8,Isolatedstorage,Media Library,我想设置从图片库中选择的图像作为背景。因此,我在IsolatedStorageSetting中获取所选照片的原始名称。但后来我无法从路径中获取文件流。。代码如下: bitmapimage.UriSource = new Uri(Settings.BackgroundPhotoUrl, UriKind.Absolute); BackgroundImg.ImageSource = bitmapimage; Settings.MyStream = e.ChosenPhoto 但是这个代码不起作用。

我想设置从图片库中选择的图像作为背景。因此,我在IsolatedStorageSetting中获取所选照片的原始名称。但后来我无法从路径中获取文件流。。代码如下:

bitmapimage.UriSource = new Uri(Settings.BackgroundPhotoUrl, UriKind.Absolute);
BackgroundImg.ImageSource = bitmapimage;
Settings.MyStream = e.ChosenPhoto
但是这个代码不起作用。也不例外。只是背景是黑色的。 因此,我尝试在IsolatedStorageSetting中保存流(我不太喜欢这个解决方案!!),但在这种情况下,我得到了一个异常:

Operation denied
代码如下:

bitmapimage.UriSource = new Uri(Settings.BackgroundPhotoUrl, UriKind.Absolute);
BackgroundImg.ImageSource = bitmapimage;
Settings.MyStream = e.ChosenPhoto
最后,我尝试将图像保存在独立存储中:

using (System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
    isf.CopyFile(e.OriginalFileName, "background" + System.IO.Path.GetExtension(e.OriginalFileName), true);
}
但在这种情况下,我也获得了一个操作拒绝异常


我怎样才能解决这个问题??Thanx

看来你误会了。流是指向文件中可以读取或写入的位置的指针。如果您正在使用照片选择器,则结果将为您提供文件流。您需要在流中读取字节,然后保存本地存储。然后您可以从那里访问图像

在我的实时倒计时应用程序中,我使用WriteableBitmap类将Jpeg保存到流中。大致如下:

var store =     
    System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
var newPath = "MyFileName.png";

if (store.FileExists(newPath)) store.DeleteFile(newPath);

var stream = store.CreateFile(newPath);

BitmapImage i = new BitmapImage();
i.SetSource(photoResult.ChosenPhoto);
WriteableBitmap imageToSave = new WriteableBitmap(i);
imageToSave.SaveJpeg(stream, 173, 173, 0, 100);

stream.Flush();
stream.Close();
这是一种流动。我必须从不同的功能中提取部分并将它们放在一起,因为应用程序允许用户首先扩展应用程序。当我为平铺保存图像时,会缩放SaveJpeg方法参数