永发信息网

string”不包含“GetExtension”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法

答案:2  悬赏:0  手机版
解决时间 2021-02-26 13:11
  • 提问者网友:雾里闻花香
  • 2021-02-25 19:40
public static void AddWater(string Path, string Path_sy, Dictionary config)
{
string s = config["maxValue"];
Image image = Image.FromFile(Path);
int width = image.Width;
int height = image.Height;
if ((width < 50) | (height < 50))
{
image.Dispose();
}
else
{
Image image2 = new Bitmap(width, height);
Graphics graphics = Graphics.FromImage(image2);
graphics.InterpolationMode = InterpolationMode.High;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.Clear(Color.Transparent);
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
image.Dispose();
graphics.Dispose();
Graphics graphics2 = Graphics.FromImage(image2);
graphics2.DrawImage(image2, 0, 0, image2.Width, image2.Height);
Font font = new Font("Verdana", 12f);
Brush brush = new SolidBrush(Color.Black);
graphics2.DrawString(s, font, brush, (float)0f, (float)0f);
graphics2.Dispose();

//下面的语句出现错误:“string”不包含“GetExtension”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“GetExtension”(是否缺少 using 指令或程序集引用?)

string str3 = Path.GetExtension(Path_sy).ToLower();
if (str3 != null)
{
if (!(str3 == ".jpg"))
{
if (str3 == ".bmp")
{
image2.Save(Path_sy, ImageFormat.Bmp);
}
else if (str3 == ".gif")
{
image2.Save(Path_sy, ImageFormat.Gif);
}
else if (str3 == ".png")
{
image2.Save(Path_sy, ImageFormat.Png);
}
}
else
{
image2.Save(Path_sy, ImageFormat.Jpeg);
}
}
image2.Dispose();
}
}
最佳答案
  • 五星知识达人网友:刀戟声无边
  • 2021-02-25 21:19
这么写:string str3 = System.IO.Path.GetExtension(Path_sy).ToLower();

你的 参数Path 和 System.IO.Path类重名了,最好重命名下参数
全部回答
  • 1楼网友:何以畏孤独
  • 2021-02-25 22:40
不明白啊 = =!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯