2D 图像旋转,几个问题

发布于 2024-08-19 20:23:43 字数 585 浏览 5 评论 0原文

我正在将“鼠标旋转”添加到我的 2D 绘图程序中。我已经让所有代码正常工作,基本上通过计算从原始鼠标单击到鼠标当前所在位置的旋转角度。

我还绘制了一个可旋转的透明矩形,而不是在每次鼠标移动事件时实际旋转图像。

现在,我的问题是这个矩形的绘制。我从图像的 x/y 位置绘制矩形,其宽度/高度是图像报告的内容。

然而,旋转矩形图像后,其新的宽度和高度要大得多,这两个屏幕截图应该有助于澄清:旋转期间,以及 旋转后再次旋转——小“手柄”显示图像的x/y/宽度/高度延伸到的位置

在第二个屏幕截图中,由于旋转,图像已被填充,有点像空白(很难用文字描述!)。例如,200x100 的图像在旋转后可能会变成 150x150(大约),这在第二次调整大小时看起来有点奇怪。

有谁知道如何解决这个问题?

I'm adding "mouse rotation" to my 2D drawing program. I've got all the code working, by basically calculating the rotation angle from the original mouse click to wherever the mouse currently is.

I also draw a transparent rectangle that rotates, instead of actually rotating the image on every mouse movement event.

Now, my problem is the drawing of this rectangle. I draw the rectangle from the image's x/y position, with its width/height being what the image reports.

However, after rotating a rectangular image, its new width and height is much bigger, as these two screenshots should help clarify: During rotation, and after rotating then rotating again -- the little "handles" show where the images' x/y/width/height extends to

In the second screenshot, because of the rotation, the image has been padded, sort of with whitespace (it's hard to describe with text!). E.g. an image that's 200x100 can end up like 150x150 (approximately) after rotating, which looks a bit strange when resizing the 2nd time.

Does anyone have an idea how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江挽川 2024-08-26 20:23:43

根据经验,切勿旋转/调整之前旋转的图像的大小,因为小错误会开始蔓延。

通常,保留原始图像的副本并根据该图像进行所有更改会更容易。

例如,第一次旋转为 5 度。第二次旋转 15 度。要渲染第二个图像,请将原始副本旋转 20 度并显示它。

不确定这是否有帮助或者我是否误读了你的问题。

As a rule of thumb, never rotate/resize a previously rotated image as the small errors will start creeping in.

Generally, it is easier to keep a copy of the original image and base ALL changes off that image.

For example, the first rotate is 5 degrees. The second rotate is 15 degrees. To render the second image, rotate the original copy 20 degrees and display that.

Not sure if that helps or if I have misread your question.

策马西风 2024-08-26 20:23:43

您可能应该跟踪图像的当前旋转,以便您可以在当前旋转时重新绘制图像周围的矩形。如果您需要旋转超过 1 个物体,则必须跟踪图层以及每个物体的旋转。

You should probably keep track of the image's current rotation, so that you can re-draw the rectangle around the image at its current rotation. If you are going to need to rotate more than 1 thing, you will have to keep track of layers, and the rotation of each one.

梦旅人picnic 2024-08-26 20:23:43

您需要存储图像的原始尺寸和当前的旋转角度,以便您可以有效地正确地取消旋转。此外,您还需要保存原始图像数据。

现在发生的情况是您的程序丢失了有关原始图像大小的信息,因此它使用它所看到的(正确的)。您想要的是从原始图像数据重新绘制,只是旋转不同。

You'll need to store the original dimensions of the image and the current angle of rotation so that you can effectively back out the rotations correctly. Also, you'll need to save the original image data.

What's happening now is that your program loses the information about the original image size, so it uses what it sees (correctly). What you want is a fresh redraw from the original image data, just with a different rotation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文