我想从图像中裁剪一个旋转的矩形。我想做的事情是这样的:
System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
// rect.RadiusX = ...; // rect.Height = ....; ..
rect.RenderTransform = new RotateTransform(angle);然后从图像中裁剪这个矩形。所有我发现的代码都从image.But中裁剪了一个System.Windows.Drawing矩形,我需要裁剪一个System.Windows.Shapes来应用旋转变换,这对于System.Windows.Drawing矩形是不适用的。
发布于 2014-02-04 18:52:17
因为你的问题缺少一些代码。因此,据我所知,给定的方法将为您提供适当的结果。如果答案不符合您的要求,请详细说明问题陈述。
public static Bitmap CropRotatedRect(Bitmap source, Rectangle rect, float angle, bool HighQuality)
{
Bitmap result = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = HighQuality ? InterpolationMode.HighQualityBicubic : InterpolationMode.Default;
using (Matrix mat = new Matrix())
{
mat.Translate(-rect.Location.X, -rect.Location.Y);
mat.RotateAt(angle, rect.Location);
g.Transform = mat;
g.DrawImage(source, new Point(0, 0));
}
}
return result;
}希望这能有所帮助。
https://stackoverflow.com/questions/21538743
复制相似问题