C# 如何在调整大小和剪切的位图中移动?
在.NETCore中,我有一个返回随机图像的控制器。假设我有一个微笑。当我调用localhost/1000/1000时,它返回一个宽度和高度分别为1000像素的笑脸图像 当我调用localhost/500/1000时,我裁剪了它: 到目前为止,我已经做到了这一点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
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开始