当我使用 Bitmap.Clone() 裁剪图像时,它会创建大于原始图像大小
的输出原始大小为:5 M
,输出裁剪图像为:28 M
如何在不损失质量且尺寸不大的情况下进行裁剪?我的代码是:
private static Image cropImage(Image img, Rectangle cropArea)
{
var bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
img.Dispose();
bmpCrop.Save(@"D:\Work\CropImage\CropImage\crop.jpg",bmpImage.RawFormat );
return (Image)(bmpCrop);
}
static void Main(string[] args)
{
string sourceimg = @"D:\Work\Crop Image\CropImage\4032x5808.jpg";
Image imageoriginal = Image.FromFile(sourceimg);
int HorX,HorY,VerX,VerY;
Console.WriteLine("Enter X 1 Cor. ");
HorX=int.Parse(Console.ReadLine());
Console.WriteLine("Enter Y 1 Cor. ");
HorY=int.Parse(Console.ReadLine());
Console.WriteLine("Enter X 2 Cor. ");
VerX=int.Parse(Console.ReadLine());
Console.WriteLine("Enter Y 1 Cor. ");
VerY= int.Parse(Console.ReadLine());
Rectangle rect = new Rectangle(HorX,HorY,VerX,VerY);
cropImage(imageoriginal, rect);
}