C#截取与缩放图片的实用技巧

在 C# 中,截取图片的一部分或者缩放图片可以通过 Graphics 类来实现。使用 Bitmap 对象加载图片,利用 Graphics.DrawImage 方法截取指定区域或缩放图片到所需尺寸。你可以设置矩形区域来截取,或者通过设置目标宽高来进行缩放。具体代码如下:

using System.Drawing;
Bitmap originalImage = new Bitmap("path_to_image");
// 截取部分
Rectangle cropArea = new Rectangle(50, 50, 200, 200);
Bitmap croppedImage = originalImage.Clone(cropArea, originalImage.PixelFormat);
// 缩放图片
Bitmap resizedImage = new Bitmap(originalImage, new Size(100, 100));

这些操作可以帮助你轻松加工图片,制作出你所需要的效果。

zip
截取图片.zip 预估大小:25个文件
folder
截取图片 文件夹
file
截取图片.suo 18KB
file
截取图片.sln 926B
folder
截取图片 文件夹
file
Form1.Designer.cs 10KB
file
Program.cs 493B
folder
obj 文件夹
folder
Debug 文件夹
file
截取图片.csproj.GenerateResource.Cache 917B
file
截取图片.Properties.Resources.resources 138KB
file
截取图片.exe 181KB
file
截取图片.Form1.resources 30KB
folder
TempPE 文件夹
file
Properties.Resources.Designer.cs.dll 5KB
file
截取图片.pdb 30KB
folder
Refactor 文件夹
file
截取图片.csproj.FileListAbsolute.txt 2KB
folder
bin 文件夹
folder
Debug 文件夹
file
截取图片.exe 181KB
file
截取图片.pdb 30KB
file
截取图片.vshost.exe.manifest 490B
file
截取图片.vshost.exe 14KB
file
Form1.cs 7KB
folder
Resources 文件夹
file
1.jpg 97KB
file
2.jpg 39KB
file
截取图片.csproj 4KB
file
Form1.resx 50KB
folder
Properties 文件夹
file
AssemblyInfo.cs 1KB
file
Settings.Designer.cs 1KB
file
Resources.resx 6KB
file
Settings.settings 249B
file
Resources.Designer.cs 3KB
zip 文件大小:708.26KB