C# 图像缩略 将图片等比例缩小的500并保存 在线等 急
答案:2 悬赏:60 手机版
解决时间 2021-04-03 15:38
- 提问者网友:留有余香
- 2021-04-03 02:25
C# 图像缩略 将图片等比例缩小的500并保存 在线等 急
最佳答案
- 五星知识达人网友:低血压的长颈鹿
- 2021-04-03 03:41
1楼的太专业了,给你个简单的,我是把宽度设为500,高度按比例缩放。
前面一大段是来设置图片名称和路径的,真正的功能 也就是后6行。
public static void Main(string[] args)
{
Console.WriteLine("请输入图片文件路径:");
string path = Console.ReadLine();
Console.WriteLine("生的图片将会保存在与原文件相同目录下!");
string currentPath = path.Substring(0, path.LastIndexOf("\"));
string fileName = path.Substring( path.LastIndexOf("\") + 1 , path.Length - path.LastIndexOf("\")-1);
string newFileName = "new" + fileName;
Image img = Image.FromFile(path);
int width = 500;
Image newImg = new Bitmap(width, img.Height * width / img.Width );
Graphics g = Graphics.FromImage(newImg);
g.DrawImage(img, 0, 0, width, img.Height * 500 / img.Width);
newImg.Save(currentPath + newFileName);
}
前面一大段是来设置图片名称和路径的,真正的功能 也就是后6行。
public static void Main(string[] args)
{
Console.WriteLine("请输入图片文件路径:");
string path = Console.ReadLine();
Console.WriteLine("生的图片将会保存在与原文件相同目录下!");
string currentPath = path.Substring(0, path.LastIndexOf("\"));
string fileName = path.Substring( path.LastIndexOf("\") + 1 , path.Length - path.LastIndexOf("\")-1);
string newFileName = "new" + fileName;
Image img = Image.FromFile(path);
int width = 500;
Image newImg = new Bitmap(width, img.Height * width / img.Width );
Graphics g = Graphics.FromImage(newImg);
g.DrawImage(img, 0, 0, width, img.Height * 500 / img.Width);
newImg.Save(currentPath + newFileName);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯