我正在尝试将图片保存到我的媒体库中。
这是我的xaml.cs文件
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Media.Imaging;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace App5
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
lstImage.ItemsSource = GetAllPhotos();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
private ImageSource GetImageSource(string fileName)
{
return new BitmapImage(new Uri(fileName, UriKind.Absolute));
}
private ObservableCollection<Photo> GetAllPhotos()
{
ObservableCollection<Photo> photos = new ObservableCollection<Photo>
{
new Photo{PhotoSource = GetImageSource("http://winartstyle.com/wp8/set1/1_0002_10453.jpg")},
new Photo{PhotoSource = GetImageSource("http://winartstyle.com/wp8/set1/1_0003_10443.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Harish.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/HarishV.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Abhi.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Suprotim.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/HarishVAlone.png")},
//new Photo{PhotoSource = GetImageSource("Images/Pinal.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Shaivi.jpg")}, new Photo{PhotoSource = GetImageSource("Images/Shobhan.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Vikram.jpg")},
//new Photo{PhotoSource = GetImageSource("Images/Host.jpg")}
};
return photos;
}
private void SaveButton_Click(object sender, EventArgs e)
{
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
}
}
这是我的xaml
<Page
x:Class="App5.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App5"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" />
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,-20,12,0">
<ListBox x:Name="lstImage" Margin="0,-20,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding PhotoSource}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
<Page.BottomAppBar>
<CommandBar IsSticky="True" >
<AppBarButton Icon="Save" Label="Save" x:Name="SaveButton" Click="SaveButton_Click" />
</CommandBar>
</Page.BottomAppBar>
</Page>
我试图做这样的事情
private void SaveButton_Click(object sender, EventArgs e)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.FileExists(System.IO.Path.Combine()) ||
store.FileExists(System.IO.Path.Combine( )) && MessageBox.Show("Overwrite the file?", "Question", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
using (var stream = store.CreateFile(System.IO.Path.Combine( )))
{
stream.Write(_imageAsByte, 0, _imageAsByte.Length);
}
}
}
}
# endregion
public byte[] _imageAsByte { get; set; }
}
}
但它没有工作
我真的可以帮助解决这个问题。 我将从我的网页上加载许多图片,如果您喜欢,可以将其保存到手机中并将其用作锁屏或开始屏幕的背景