Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在调整大小和剪切的位图中移动?_C#_Drawing - Fatal编程技术网

C# 如何在调整大小和剪切的位图中移动?

C# 如何在调整大小和剪切的位图中移动?,c#,drawing,C#,Drawing,在.NETCore中,我有一个返回随机图像的控制器。假设我有一个微笑。当我调用localhost/1000/1000时,它返回一个宽度和高度分别为1000像素的笑脸图像 当我调用localhost/500/1000时,我裁剪了它: 到目前为止,我已经做到了这一点 Rectangle rect = new Rectangle(0,0,width,height); rect.Intersect(new Rectangle(0, 0, image.Width, ima

在.NETCore中,我有一个返回随机图像的控制器。假设我有一个微笑。当我调用localhost/1000/1000时,它返回一个宽度和高度分别为1000像素的笑脸图像

当我调用localhost/500/1000时,我裁剪了它:

到目前为止,我已经做到了这一点

        Rectangle rect = new Rectangle(0,0,width,height);

        rect.Intersect(new Rectangle(0, 0, image.Width, image.Height));

        image = ((Bitmap)image).Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);

        var returnedImage = ImageUtils.ToStream(image, System.Drawing.Imaging.ImageFormat.Jpeg);

        return returnedImage;
我不想半个笑脸,而是想从中间剪成这样:

我该怎么做?你试过这个吗

Rectangle rect = new Rectangle(image.Width / 4, 0, width, height);
编辑添加说明:在图像的第一个四分之一处开始矩形使其覆盖所需的部分,因此如果您想要右半部分,则从image.Width/2开始