Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
添加将插画设置为桌面壁纸的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
YukinoShary committed May 9, 2020
1 parent abdbff2 commit ff3d769
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions PixivFSUWP/BigImage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<InkToolbarStencilButton/>
</InkToolbar>
</CommandBar.Content>
<AppBarButton x:Name="btnSetWallpaper" Icon="SetLockScreen" x:Uid="SetWallpaper" Label="设置为壁纸" Click="btnSetWallpaper_Click"/>
<AppBarButton x:Name="btnSaveImage" Icon="Save" x:Uid="SaveImage" Click="BtnSaveImage_Click"/>
<AppBarToggleButton x:Name="btnDraw" Icon="Edit" x:Uid="Draw" Unchecked="BtnDraw_Unchecked" Checked="BtnDraw_Checked"/>
</CommandBar>
Expand Down
25 changes: 25 additions & 0 deletions PixivFSUWP/BigImage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Graphics.Canvas;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
Expand All @@ -12,6 +13,7 @@
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Provider;
using Windows.System.UserProfile;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
Expand Down Expand Up @@ -131,6 +133,28 @@ private async void BtnSaveImage_Click(object sender, RoutedEventArgs e)
await saveImage();
}

private async void btnSetWallpaper_Click(object sender, RoutedEventArgs e)
{
if (UserProfilePersonalizationSettings.IsSupported())
{
UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
StorageFile file = await parameter.ImageCache.CopyAsync(ApplicationData.Current.LocalFolder, "WallpaperImage", NameCollisionOption.ReplaceExisting);
if (!await settings.TrySetWallpaperImageAsync(file))
{
Debug.WriteLine(file.Path);
var messageDialog = new MessageDialog("更换壁纸失败");
await messageDialog.ShowAsync();
}
else
await ShowTip("已更换壁纸");
}
else
{
var messageDialog = new MessageDialog("您的设备不支持更换壁纸");
await messageDialog.ShowAsync();
}
}

List<(string, int)> tips = new List<(string, int)>();
bool _tip_busy = false;

Expand Down Expand Up @@ -254,5 +278,6 @@ private async Task saveStrokes()
await ShowTip(GetResourceString("NoInkPlain"));
}
}

}
}
2 changes: 2 additions & 0 deletions PixivFSUWP/Data/BigImageDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml.Media.Imaging;

namespace PixivFSUWP.Data
Expand All @@ -14,5 +15,6 @@ public class BigImageDetail
public int Width { get; set; }
public int Height { get; set; }
public byte[] Image { get; set; }
public StorageFile ImageCache { get; set; }
}
}
6 changes: 4 additions & 2 deletions PixivFSUWP/IllustDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,16 @@ private async void ImageList_ItemClick(object sender, ItemClickEventArgs e)
{

var Item = e.ClickedItem as ViewModels.ImageItemViewModel;
var tmpFileName = illust.OriginalUrls[0].ToString().Split('/').Last();
await Data.OverAll.ShowNewWindow(typeof(BigImage), new Data.BigImageDetail()
{
Title = illust.Title,
Width = Item.ImageSource.PixelWidth,
Height = Item.ImageSource.PixelHeight,
Author = illust.Author,
Image = await Data.OverAll.ImageToBytes(Item.ImageSource)
});
Image = await Data.OverAll.ImageToBytes(Item.ImageSource),
ImageCache = await Data.CacheManager.GetCachedFileAsync(tmpFileName)
});
}

private async void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
Expand Down

0 comments on commit ff3d769

Please sign in to comment.