1
我试图实现更改锁定图像的Windows Phone 8应用程序。该图像写入独立存储中的部分代码如下:原生Windows Phone 8图像API
private async void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
store.Remove();
}
BitmapImage bi = new BitmapImage();
bi.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bi);
byte[] buffer = null;
using (var ms = new System.IO.MemoryStream())
{
int quality = 80;
e.ChosenPhoto.Seek(0, SeekOrigin.Begin);
// TODO: Crop or rotate here if needed
wb.SaveJpeg(ms, wb.PixelWidth, wb.PixelHeight, 0, quality);
buffer = ms.ToArray();
}
var isoFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var nextImageName = Guid.NewGuid() + ".jpg";
var newImageFile = await isoFolder.CreateFileAsync(nextImageName, Windows.Storage.CreationCollisionOption.FailIfExists);
using (var wfs = await newImageFile.OpenStreamForWriteAsync())
{
wfs.Write(buffer, 0, buffer.Length);
}
Windows.Phone.System.UserProfile.LockScreen.SetImageUri(new Uri("ms-appdata:///Local/" + nextImageName, UriKind.Absolute));
MessageBox.Show("You have successfully set a new background");
}
}
在你看到下面的注释代码的中间:
// TODO: Crop or rotate here if needed
我的问题是:
本地图像裁剪的代码是什么? (例如,像你看到的,当你选择通过原生的Windows Phone锁屏设置在锁定画面中的照片之一)
谢谢佩恩先生)像一个魅力工程!有没有办法将photoChooser.PixelHeight和Widht绑定到应用程序运行的设备的比例? –
这里的答案我的最后一个问题: '如果(App.Current.Host.Content.ScaleFactor == 100){ // WVGA } 否则,如果(App.Current.Host.Content.ScaleFactor == 160) { // WXGA } 否则如果(App.Current.Host.Content.ScaleFactor == 150){ // 720p的 }' –
“为锁屏推荐的锁定屏幕图像尺寸为480像素X 800px或960px X 1708px。如果提供了较大的图像,它将从中心裁剪并设置在锁定屏幕上:如果提供了较小的图像,则它将被拉伸以适应屏幕(并且可能会模糊/划伤)。 (http://developer.nokia.com/Community/Wiki/Dynamic_Lock_Screen_for_Windows_Phone_8) –