0
wpf를 처음 사용하는 이유는 코드별로 바탕 화면 배경 무늬를 변경하는 방법을 알려주시겠습니까?Wpf에서 바탕 화면 이미지를 변경하는 방법 C#
저는이 문제에 대해 몇 가지 주제를 읽었지 만 WPF의 해결책을 생각해 낼 수 없습니다.
바탕 화면 배경 무늬가 SetWallpaper를 호출해도 변경되지 않습니다.
public static ArrayList images;
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
public enum StyleS_Wallpaper : int
{
Tiled, Centered, Stretched
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(
int uAction, int uParam, string lpvParam, int fuWinIni);
private void OpenExecuted(object sender, ExecutedRoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = "c:\\";
ofd.Multiselect = true;
ofd.Filter = "Image Files (*.jpg)|*.jpg|Image Files (*.png)|*.png|Image File (*.gif)|*.gif|Image File (*.bmp)|*.bmp|Image Files (*.png)|*.png";
//ofd.RestoreDirectory = true;
Nullable<bool> result = ofd.ShowDialog();
if (result == true)
{
FileNames = ofd.FileNames;
if (images == null)
{
images = new ArrayList();
newlist = new List<string>();
}
for (int i = 0; i < FileNames.Length; i++)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.UriSource = new Uri(FileNames[i]);
bitmap.EndInit();
images.Add(bitmap);
newlist.Add(FileNames[i]);
NextCount++;
}
}
}
public void SetWallpaper(string path,StyleS_Wallpaper selected)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (selected == StyleS_Wallpaper.Stretched)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (selected == StyleS_Wallpaper.Centered)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (selected == StyleS_Wallpaper.Tiled)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}
SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
path,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
private void CenterImage_Click(object sender, RoutedEventArgs e)
{
BitmapImage img = (BitmapImage)images[currentPicture];
string Path = img.UriSource.ToString();
string name = "0";
// TrimingString Returns the string path as C:\Documents and Settings\ProZec\Desktop\WallPapers
TrimingString(Path, ref name, true);
SetWallpaper(name, StyleS_Wallpaper.Centered);
}
필자는 bmp FILE을 사용하고 있습니다. 내 centerImage_Click 메서드에서 볼 수 있습니다. 내가 얻고있는 문제를 지정할 수 있습니까 –
디스크의 파일이 실제로 BMP 파일입니까? 또는 JPG 또는 다른 형식입니까? BitmapImage 클래스는 여러 형식에 사용할 수 있습니다. 또한이 스레드를보십시오 : http://www.xtremedotnettalk.com/showthread.php?t=78085 – Jason
기본적으로 WPF ImageControl에서 작업 중이므로 wpf 이미지 컨트롤에서만 비트 맵 이미지 만 받아들입니다. 그래서 아래 bmp 다른 형식으로 변환 오전 내 코드를 위의 내 코드를 확인할 수 있습니다 내 이미지 변환 표시하려면 편집 오전 –