gpt4 book ai didi

c# - 覆盖现有图像

转载 作者:IT王子 更新时间:2023-10-29 04:24:25 26 4
gpt4 key购买 nike

我有这个代码

    private void saveImage()
{
Bitmap bmp1 = new Bitmap(pictureBox.Image);
bmp1.Save("c:\\t.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// Dispose of the image files.
bmp1.Dispose();
}

我的驱动器 "c:\" 中已经有一张图片 t.jpg
每次我的程序运行时,我都想用一个新图像替换它。但是出现 GDI+ 错误
我该如何解决?

最佳答案

如果您的图像已经存在,您必须将其删除。

private void saveImage()
{
Bitmap bmp1 = new Bitmap(pictureBox.Image);

if(System.IO.File.Exists("c:\\t.jpg"))
System.IO.File.Delete("c:\\t.jpg");

bmp1.Save("c:\\t.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// Dispose of the image files.
bmp1.Dispose();
}

关于c# - 覆盖现有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8905714/

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