平移/旋转先前绘制的矩形,这可能吗? [英] Translate/Rotate previously drawn rectangle, is this possible?

查看:86
本文介绍了平移/旋转先前绘制的矩形,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本的bmp,​​为便于访问,bmp会根据用户选项进行相应的旋转。问题:每当图像旋转时,文本就会反转。
(只有严格的角度,90、180等)

I have a bmp with text, for ease of access the bmp rotates accordingly to the user options. Problem: the text gets inverted whenever the image rotates. (only strict angles, 90, 180, etc)

可能的解决方案:
将文本旋转180º,然后使用常规旋转,这样它不会被镜像吗?

Possible solution: Rotate the text at 180º then use the regular rotation, so that it doesnt get mirrored?

我尝试了以下方法,在文本周围创建了一个矩形并将其旋转。

I tried this the following way, I create a rectangle around the text and turn it.

    Rectangle r1 = new Rectangle((int)(ecobdesenho / 10) / 2 + esp - 15, esp - 25, 25, 12);
            using (Matrix m = new Matrix())
            {

                m.RotateAt(180, new PointF((int)(ecobdesenho / 10) / 2 + esp - 15 + (25 / 2),
                                          esp - 25 + (12 / 2)));


                 g.Transform = m;
                 g.DrawRectangle(new Pen(Color.Black), r1);
                 g.DrawString("e/10", fnt2, new SolidBrush(Color.Black), (int)(ecobdesenho / 10) / 2 + esp - 15, esp - 25); //15 para tras, 15 para cima

                g.ResetTransform();
            }

然后,我在绘图之前为bmp提供旋转:

Then, i provide the bmp with the rotation before its drawings:

            g.TranslateTransform((float)(xWcorrigido / 2 + esp), (float)(yWcorrigido / 2 + esp));
            g.RotateTransform(180);
            g.TranslateTransform((float)(-xWcorrigido / 2 - esp), (float)(-yWcorrigido / 2 - esp)); 

但是,此组合不会影响上一个文本。我试图将其放置在使用Matrix括号内,但是无论如何,它都没有应用整个转换过程。

However this combination doesnt affect the previous text. I tried to place it inside the using Matrix brackets, but regardless of it, it doesnt apply the whole transformation process.

我也可以,首先使用通用翻译,然后然后将文本放在非常特定的方框中,但是这样做会避免我要避免的工作量。

I could too, first use the general translation, and then turn the text at very specific boxes, but it would give the same amount of work i'm trying to avoid.

有任何提示吗?我的大脑已经受了这么多可能的组合伤害

Any hint? My brain already hurts with so many possible combinations

推荐答案

解决方案是在矩阵内应用变换,对于矩阵,例如

The solution is applying the transformation within the matrix, and for the matrix, like this:

        Rectangle r1 = new Rectangle((int)(ecobdesenho / 10) / 2 + esp - 15, esp - 25, 25, 12);
        using (Matrix m = new Matrix())
        {  
            m.TranslateTransform((float)(xWcorrigido / 2 + esp), (float)(yWcorrigido / 2 + esp));
            m.RotateTransform(180);
            m.TranslateTransform((float)(-xWcorrigido / 2 - esp), (float)(-yWcorrigido / 2 - esp)); 

            m.RotateAt(180, new PointF((int)(ecobdesenho / 10) / 2 + esp - 15 + (25 / 2),
                                      esp - 25 + (12 / 2)));


             g.Transform = m;
             g.DrawRectangle(new Pen(Color.Black), r1);
             g.DrawString("e/10", fnt2, new SolidBrush(Color.Black), (int)(ecobdesenho / 10) / 2 + esp - 15, esp - 25); //15 para tras, 15 para cima

            g.ResetTransform();
        }

这篇关于平移/旋转先前绘制的矩形,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆