在不使用 GDI 裁剪图像边缘的情况下旋转图像的最快方法是什么?
有一些非常漫长且饥饿的算法可以做到这一点,但到目前为止我还没有想出或发现任何特别快的算法。
There are some looooong and hungry algorithms for doing so, but as of yet I haven't come up with or found anything particularly fast.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最快的方法是使用 LockBits 直接使用不安全调用来操作图像内存。听起来很可怕,但其实很简单。如果您搜索 LockBits,您会发现大量示例,例如此处。
有趣的是:
一旦你有了 BitmapData,你就可以传递像素并将它们映射到新图像中(再次使用 LockBits)。这比使用
Graphics
API 要快得多。The fastest way is to this is to use unsafe calls to manipulate the image memory directly using
LockBits
. It sounds scary but it's pretty straight forward. If you search for LockBits you'll find plently of examples such as here.The interesting bit is:
Once you have the BitmapData you can pass the pixels and map them into a new image (again using LockBits). This is significantly quicker than using the
Graphics
API.这就是我最终所做的(经过大量的持续研究以及 TheCodeKing 提供的有用链接):
干杯!
Here's what I ended up doing (after an extensive amount of continued research, and the helpful link provided by TheCodeKing):
Cheers!
这应该在 C# 中旋转图像。它在做什么?
我还没有对 GDI+ 做过太多实验。记得在绘制图像后反转旋转。
This should rotate the image in C#. What is it doing instead?
I haven't experimented too much with GDI+. Remember to reverse the rotation after the image is drawn.
这个答案返回它应该绘制的偏移量和已经旋转的图像。它的工作原理是在不剪裁角度的情况下将新图像重新创建到它应该的大小。最初由 #C# IRC 聊天室和 Bloodyaugust 的 Hisenburg 编写。
This answer returns both the offset it should be drawn on and the image which has been rotated.It works by recreating the new image to the size it should be without clipping the angles. Originally written by Hisenburg from the #C# IRC chatroom and Bloodyaugust.