在 C# 中调整图像文件的大小,至少来自那些常用的(bmp、jpg 等)
我发现了很多片段,但不是一个真正完整的片段。所以我要再问一次,谁来这里可能会使用完整的文件:
这只是输出具有相同宽度和高度的文件。
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace PicResize
{
class Program
{
static void Main(string[] args)
{
ResizeImage(0, 0, 200, 200);
}
public static void ResizeImage(int X1, int Y1, int Width, int Height)
{
string fileName = @"C:\testimage.jpg";
using (Image image = Image.FromFile(fileName))
{
using (Graphics graphic = Graphics.FromImage(image))
{
// Crop and resize the image.
Rectangle destination = new Rectangle(0, 0, Width, Height);
graphic.DrawImage(image, destination, X1, Y1, Width, Height, GraphicsUnit.Pixel);
}
image.Save(@"C:\testimagea.jpg");
}
}
}
}
所以,既然周围没有很好的例子,这是如何工作的?我需要在这里修复什么?
谢谢