剪切/删除图像的一部分(JPG)

时间:2013-02-22 05:27:56

标签: c# image crop editing

有没有办法以编程方式从JPG图像中删除JPG图像(矩形)的部分。通过一些试验和错误,我可以调整XY坐标以适应我的要求(削减用户名框)

所有问题似乎都需要裁剪的矩形部分,而我需要将原始图像用矩形部分清空。

1 个答案:

答案 0 :(得分:1)

此示例代码采用图像的右下象限。它应该足以让你与之合作并获得一个想法::

string path = "C:\\test.jpg";
using (Bitmap orignal = new Bitmap(path))
{
        using (Bitmap newimage = new Bitmap((int)(orignal.Width * 0.5), (int)(orignal.Height * 0.5)))
        {
                using (Graphics newgraphics = Graphics.FromImage(newimage))
                {
                        newgraphics.DrawImage(orignal, 0, 0, new Rectangle(newimage.Width, newimage.Height, orignal.Width - newimage.Width, orignal.Height - newimage.Height), GraphicsUnit.Pixel);
                        newgraphics.Flush();
                }


                newimage.Save(new System.IO.FileInfo(path).DirectoryName + "out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
}