C#在小顶部裁剪图像

0 c#

我有一个图像,我想裁剪图像的顶部并将图像保存在C#中.我该怎么办呢?

TSt*_*per 5

以下是一些记录良好的裁剪代码:

 try
 {
    //create the destination (cropped) bitmap
    Bitmap bmpCropped = new Bitmap(100, 100);
    //create the graphics object to draw with
    Graphics g = Graphics.FromImage(bmpCropped);

    Rectangle rectDestination = new Rectangle(0, 0, bmpCropped.Width, bmpCropped.Height);
    Rectangle rectCropArea = new Rectangle(myX, myY, myCropWidth, myCropHeight);

    //draw the rectCropArea of the original image to the rectDestination of bmpCropped
    g.DrawImage(myOriginalImage, rectDestination, rectCropArea,GraphicsUnit.Pixel);
    //release system resources
 }
 finally
 {
     g.Dispose();
 } 
Run Code Online (Sandbox Code Playgroud)

  • +1,但你应该使用"using"(或try/finally)来确保调用g.Dispose() (2认同)