C# 将StorageFile转换为WriteableBitmap WP8.1 Silverlight

C# 将StorageFile转换为WriteableBitmap WP8.1 Silverlight,c#,silverlight,windows-phone-8.1,C#,Silverlight,Windows Phone 8.1,我正在开发这个应用程序,我可以从图片库中获取所有图片作为StorageFile数据类型。现在我想将其更改为writeablebitmap,应用草图过滤器并在图像控件中显示。有人能帮我将数据类型从StorageFile更改为writeablebitmap吗 这是我的密码: StorageFolderpicturesFolder = KnownFolders.PicturesLibrary; IReadOnlyList<IStorageFile> file = await pictur

我正在开发这个应用程序,我可以从图片库中获取所有图片作为StorageFile数据类型。现在我想将其更改为writeablebitmap,应用草图过滤器并在图像控件中显示。有人能帮我将数据类型从StorageFile更改为writeablebitmap吗

这是我的密码:

StorageFolderpicturesFolder = KnownFolders.PicturesLibrary;

IReadOnlyList<IStorageFile> file = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);

if(file.Count > 0)

 {

foreach(StorageFile f in file)

 { 

// the code for changing the data type will go here

}
StorageFolderpicturesFolder=KnownFolders.PicturesLibrary;
IReadOnlyList file=wait picturesFolder.getfileasync(CommonFileQuery.OrderByDate);
如果(file.Count>0)
{
foreach(文件中的存储文件f)
{ 
//更改数据类型的代码将显示在此处
}

试试这个,它应该可以工作:

IReadOnlyList<IStorageFile> files = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);

if(files.Count > 0)
{
    var images = new List<WriteableBitmap>();
    foreach(var f in files)
    { 
         var bitmap = new WriteableBitmap(500, 500);
         using (var stream = await f.OpenAsync(FileAccessMode.ReadWrite))
         {
             bitmap.SetSource(stream);
         }
         images.Add(bitmap);
    }
}
IReadOnlyList files=wait picturesFolder.getfileasync(CommonFileQuery.OrderByDate);
如果(files.Count>0)
{
var images=新列表();
foreach(文件中的var f)
{ 
var位图=新的可写位图(500500);
使用(var stream=wait f.OpenAsync(FileAccessMode.ReadWrite))
{
设置源(流);
}
添加(位图);
}
}

这个代码对我很有用

if (file.Count > 0)
{          
    foreach (StorageFile f in file)
    {
        ImageProperties properties = await f.Properties.GetImagePropertiesAsync();
        WriteableBitmap bmp = new WriteableBitmap((int)properties.Width, (int)properties.Height);
        bmp.SetSource((await f.OpenReadAsync()).AsStream());

        // Ready to go with bmp
    }
}

它在bitmap.SetSource(stream)处出现此错误;“与'System.Windows.Media.Imaging.BitmapSource.SetSource(System.IO.stream)'匹配的最佳重载方法具有一些无效参数”因为他正在设置硬编码位图大小。试试我的解决方案。好的,我知道了,你使用Silverlight,我们的解决方案是针对WinRT的,我会尝试另一种方法。它可以工作:D非常感谢你。我很高兴我能帮上忙:没有
.AsStream()
SetSource()
可以处理
irandomaccesstream