首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在ListView中保存所有图像

在ListView中保存所有图像
EN

Stack Overflow用户
提问于 2015-08-24 03:44:38
回答 2查看 78关注 0票数 1

我正在ListView.I中加载一组来自Vk.com的图像,我希望能够下载/保存任何列表中的所有图像到手机的图库中,无论是在一个简单的事件中,还是在默认情况下。我该怎么做呢?这是XAML。

代码语言:javascript
运行
复制
<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>
EN

Stack Overflow用户

发布于 2015-08-26 01:58:33

您已经将其标记为WP8和WP8.1。下面的代码是针对8的,但是对于8.1应该不会占用太多的工作。

您可以下载图像并将其保存到用户库中,如下所示:

代码语言:javascript
运行
复制
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"替换为图像的真实名称。

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32170784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档