为什么不能应用 Graphics.RotateTransform() ?
我有以下功能:
static private Image CropRotate(Image wholeImage, Rectangle cropArea)
{
Bitmap cropped = new Bitmap(cropArea.Width, cropArea.Height);
using(Graphics g = Graphics.FromImage(cropped))
{
g.DrawImage(wholeImage, new Rectangle(0, 0, cropArea.Width, cropArea.Height), cropArea, GraphicsUnit.Pixel);
g.RotateTransform(180f);
}
return cropped as Image;
}
它应该裁剪图像,然后旋转生成的子图像。但实际上,它只执行裁剪。
为什么没有应用RotateTransform()
?
I have the following function:
static private Image CropRotate(Image wholeImage, Rectangle cropArea)
{
Bitmap cropped = new Bitmap(cropArea.Width, cropArea.Height);
using(Graphics g = Graphics.FromImage(cropped))
{
g.DrawImage(wholeImage, new Rectangle(0, 0, cropArea.Width, cropArea.Height), cropArea, GraphicsUnit.Pixel);
g.RotateTransform(180f);
}
return cropped as Image;
}
It's supposed to crop an image, then rotate the resulting sub-image. In actuality though, it only performs the crop.
Why is RotateTransform()
not being applied?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过将
RotateTransform()
放在DrawImage()
之前?msdn 页面上的示例 显示了在进行任何绘图之前应用的转换完毕。
Have you tried putting the
RotateTransform()
before theDrawImage()
?The example on the msdn page shows the transformation being applied before any drawing is done.
RotateTransform
调用会更改当前的变换矩阵,这会对所有后续操作产生影响。它根本不转换已经输出的操作。这对于任何更改变换矩阵的操作(例如 ScaleTransform )都是相同的。确保在执行要转换的操作之前调用这些函数 - 在本例中,是在调用
DrawImage
之前。您可以使用它来执行诸如
第一个和最后一个绘制输出不会被转换,但中间的输出将受到旋转和缩放(按顺序)的影响。
The
RotateTransform
call alters the current transform matrix, which has an effect on all subsequent operations. It does not transform the already output operations at all. This is the same for any of the operations that change the transform matrix (likeScaleTransform
).Make sure you call these before you perform the operations you want transformed - in this case, before the call to
DrawImage
.You can use this to do something like
the first and last draw outputs will not be transformed, but the middle one would be affected by both the rotate and scale (in that order).