如何更改锁屏背景(查找windows.system.UserProfile.dll)?

How to Change the LockScreen back ground (find windows.system.UserProfile.dll)?

我启动了一个 windows 表单应用程序,它从文件中导入图像并存储它们,并为每个图像指定一个单选按钮。

它有一个名为 'Lock' 的按钮 因此,如果用户 select 一个单选按钮,然后按下该按钮,应用程序应更改锁定屏幕图像,然后锁定屏幕。

但是我不知道怎么设置图片和锁屏

我后来用谷歌搜索,关于 LockScreen.blabla 的答案对我不起作用,因为我不能使用 windows.system.userprofile;

如果有人让我组装,我会做这件事。

有事件:

private void rB_CheckedChanged(object sender, EventArgs e)
        {
            MyRadioButton radioButton = sender as MyRadioButton;
            pictureBox1.Image = radioButton.Image;
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
                foreach (Control control in FindForm().Controls)
                {
                    if (control.GetType() == typeof(MyRadioButton))
                    {
                        MyRadioButton mrb = control as MyRadioButton;
                        if (mrb.Checked == true)
                        {
                            mrb.Image = pictureBox1.Image;
                        }
                    }
                }
            }
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            //should set the lock screen background

            LockScreen.LockScreen.SetImageFileAsync(imagefile);//shows error 'the name lock screen does not exist
        }

我已经制作了一个 UWP 应用程序来使用 LockScreen class 提供的 windows.userProfile.dll 事件更改为:


        private Dictionary<string, string> Images = new Dictionary<string, string>();
        private async void btnLock_Click(object sender, RoutedEventArgs e)
        {
            string path;
            if (Images.TryGetValue(selectedRadioButton.Name, out path))
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);
                await LockScreen.SetImageFileAsync(file);
                try
                {
                    HttpClient httpClient = new HttpClient();
                    Uri uri = new Uri("http://localhost:8080/lock/");

                    HttpStringContent content = new HttpStringContent(
                        "{ \"pass\": \"theMorteza@1378App\" }",
                        UnicodeEncoding.Utf8,
                        "application/json");

                    HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(
                        uri,
                        content);

                    httpResponseMessage.EnsureSuccessStatusCode();
                    var httpResponseBody = await httpResponseMessage.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

private async void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                using (var imageStream = await file.OpenReadAsync())
                {
                    var bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(imageStream);
                    image.Source = bitmapImage;
                }
                StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                await file.CopyAsync(storageFolder, selectedRadioButton.Name+file.FileType,NameCollisionOption.ReplaceExisting);
                addOrUpdate(selectedRadioButton.Name, Path.Combine(storageFolder.Path, selectedRadioButton.Name + file.FileType));
                save();
            }
        }
        private async void rb_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            selectedRadioButton = rb;
            btnBrowse.IsEnabled = true;
            string path;
            if (Images.TryGetValue(rb.Name, out path))
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);
                using (var imageStream = await file.OpenReadAsync())
                {
                    var bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(imageStream);
                    image.Source = bitmapImage;
                }
            }
        }
        private void addOrUpdate(string key, string image)
        {
            if (Images.Keys.Contains(key))
            {
                Images.Remove(key);
                Images.Add(key, image);
            }
            else
            {
                Images.Add(key, image);
            }
        }

        private async void save()
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile file = await storageFolder.CreateFileAsync("sample.txt", CreationCollisionOption.ReplaceExisting);
            await FileIO.WriteTextAsync(file, JsonConvert.SerializeObject(Images));
        }

        private async void load()
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile sampleFile = await storageFolder.GetFileAsync("sample.txt");
            string fileText = await FileIO.ReadTextAsync(sampleFile);
            try
            {
                Images = JsonConvert.DeserializeObject<Dictionary<string, string>>(fileText);
            }
            catch (Exception)
            {
            }
        }

并且您可以在锁定按钮单击事件中看到对 Web 服务器的请求,因为您不能直接在 UWP 应用程序中锁定屏幕,您可以按照其余部分操作你的问题在我的 到问题 "why I can't directly lock screen in UWP app?and how to do so?".