gpt4 book ai didi

c# - 适合/填充图像?

转载 作者:行者123 更新时间:2023-11-30 15:28:36 27 4
gpt4 key购买 nike

我正在制作一个简单的程序来更改我的计算机背景。我在网上发现了一个stackoverflow问题,或多或少涵盖了我想做的事情。我现在可以成功地将我的墙纸更改为平铺、居中和从在线图像 URL 拉伸(stretch)。但是,在控制面板中,可以选择将墙纸置于“适合”和“填充”位置。如何以编程方式将墙纸设置为适合/填充模式?

相关代码:

public enum Style : int
{
Tiled,
Centered,
Stretched
}
public class Wallpaper
{
public Wallpaper() { }
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

public void Set(string URL, Style style)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
System.Drawing.Image img = Image.FromStream(stream);

string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp);
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (style == Style.Stretched)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Centered)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Tiled)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}
SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
tempPath,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
}

fit/fill 键不可用吗?在网上查了一会儿,只找到平铺的、居中的、拉伸(stretch)的。

最佳答案

这可能对你有帮助。

摘自 Set the desktop wallpaper

   case WallpaperStyle.Fit: // (Windows 7 and later)
key.SetValue(@"WallpaperStyle", "6");
key.SetValue(@"TileWallpaper", "0");
break;
case WallpaperStyle.Fill: // (Windows 7 and later)
key.SetValue(@"WallpaperStyle", "10");
key.SetValue(@"TileWallpaper", "0");
break;

我相信您可以轻松地将其适应您的代码。

关于c# - 适合/填充图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25434659/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com