我正在ListView.I中加载一组来自Vk.com的图像,我希望能够下载/保存任何列表中的所有图像到手机的图库中,无论是在一个简单的事件中,还是在默认情况下。我该怎么做呢?这是XAML。
<Page.BottomAppBar>
<CommandBar>
<AppBarButton FontSize="15" FontFamily="Times New Roman" Icon="Back" Label="Albums" Click="AppBarButton_Click"/>
</CommandBar>
</Page.BottomAppBar>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="*"> </RowDefinition>
</Grid.RowDefinitions>
<TextBlock x:Name="MyTextBlock" FontSize="35" HorizontalAlignment="Center"></TextBlock>
<ListView Grid.Row="1"
ItemsSource="{Binding}"
SelectionMode="None"
IsItemClickEnabled="False"
>
<ListView.ItemTemplate>
<DataTemplate>
<Image Stretch="UniformToFill" Source="{Binding image_final}"
AutomationProperties.Name="{Binding Title}"
Width="Auto"
Height="Auto"
></Image>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>发布于 2015-08-26 01:58:33
您已经将其标记为WP8和WP8.1。下面的代码是针对8的,但是对于8.1应该不会占用太多的工作。
您可以下载图像并将其保存到用户库中,如下所示:
using Microsoft.Xna.Framework.Media;
using System.Windows.Media.Imaging;
using System.IO;
WebClient client = new WebClient();
client.OpenReadCompleted += (s, ev) =>
{
var streamResourceInfo = new StreamResourceInfo(ev.Result, null);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(streamResourceInfo.Stream);
WriteableBitmap bmp = new WriteableBitmap(bitmap);
MediaLibrary library = new MediaLibrary();
using (MemoryStream stream = new MemoryStream())
{
Extensions.SaveJpeg(bmp, stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
library.SavePicture("imagename.jpg", stream.ToArray());
}
MessageBox.Show("The picture has been saved to your Pictures Hub", "Success!", MessageBoxButton.OK);
};
client.OpenReadAsync(new Uri("http://example.com/imageurl.jpg"));显然,将正确的图像URL放在最后一行。并可选择将"imagename.jpg"替换为图像的真实名称。
发布于 2015-08-29 17:31:37
这个链接真正解释了一切:保存图像,并将它们组织到文件夹中。绝对值得一读。
解释:
//Create a storage folder in the Pictures Library:
StorageFolder AppFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("XYZ", CreationCollisionOption.OpenIfExists);
//Naming and storing the file:
var uri = imageuri; //image uri
var filename = Path.GetFileName(uri.LocalPath); //designates file name
var thumbnail = RandomAccessStreamReference.CreateFromUri(uri);
var remoteFile = await StorageFile.CreateStreamedFileFromUriAsync(filename, uri, thumbnail);
await remoteFile.CopyAsync(albumname, filename, NameCollisionOption.FailIfExists); //Fail if argument filename is a string by which a file is already saved.我希望这能帮到你。
https://stackoverflow.com/questions/32170784
复制相似问题