如何在 WinForms 中绘制图像反射?

发布于 2024-08-17 03:19:43 字数 318 浏览 1 评论 0原文

我想在 C# (WinForms) 中绘制图像的反射,因此我需要能够水平翻转图像。我知道我可以使用 image.RotateFlip 来做到这一点,但这种方法的问题是我必须翻转图像两次,以便我可以在下一次绘制时再次将其右侧向上绘制。每个图像的每个绘制执行两次似乎很慢。

我想在绘制图像时进行翻转,所以我只需要翻转一次,但我找不到任何方法来做到这一点。这可能吗?

我考虑过的另一种方法是以某种方式翻转图形对象,正常绘制图像,然后将图形对象翻转回来,以便下一次绘制是正确的。如果这比翻转图像两次更快,可以吗?

另外,我不想在内存中保留 2 个图像,因此我无法复制图像并翻转克隆。

I want do draw a reflection in C# (WinForms) of an image, so I need to be able to flip the image horizontally. I know I can do this with image.RotateFlip, but the problem with this approach is that I have to flip the image twice so I can draw it again the right side up on the next paint. Doing this twice per paint per image seems to be slow.

I would like to do the flip when I draw the image so I only have to flip it once, but I can't find any way to do this. Is this possible?

Another approach I've considered is somehow flipping the graphics object, drawing the image normally, and then flipping the graphics object back so that the next paint is correct. If this is faster than flipping the image twice, is it possible to do?

Also, I don't want to keep 2 images in memory, so I can't copy the image and flip the clone.

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

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

发布评论

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

评论(2

守不住的情 2024-08-24 03:19:43

此处 获取此代码并检查一下是否是任何帮助。

using System;
using System.Drawing;
using System.Windows.Forms;

class ImageReflection: Form
{
     Image image = Image.FromFile("Color.jpg");

     public static void Main()
     {
          Application.Run(new ImageReflection());
     }
     public ImageReflection()
     {
          ResizeRedraw = true;

     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }     
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          int cxImage = image.Width;
          int cyImage = image.Height;

          grfx.DrawImage(image, cx / 2, cy / 2,  cxImage,  cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2, -cxImage,  cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2,  cxImage, -cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, -cyImage);
     }
}

Got this code from here and check out and see if it is of any help.

using System;
using System.Drawing;
using System.Windows.Forms;

class ImageReflection: Form
{
     Image image = Image.FromFile("Color.jpg");

     public static void Main()
     {
          Application.Run(new ImageReflection());
     }
     public ImageReflection()
     {
          ResizeRedraw = true;

     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }     
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          int cxImage = image.Width;
          int cyImage = image.Height;

          grfx.DrawImage(image, cx / 2, cy / 2,  cxImage,  cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2, -cxImage,  cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2,  cxImage, -cyImage);
          grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, -cyImage);
     }
}
感悟人生的甜 2024-08-24 03:19:43

编辑

<罢工>
也是这样的吗?

     draw(new Bitmap (img).rotateflip(param))


好的,rotateflip 不返回图像

看看这个,旋转翻转只需翻转一次就足够了。不?

RotateNoneFlipNone  Specifies no rotation and no flipping.
Rotate90FlipNone    Specifies a 90-degree rotation without flipping.
Rotate180FlipNone   Specifies a 180-degree rotation without flipping.
Rotate270FlipNone   Specifies a 270-degree rotation without flipping.
RotateNoneFlipX Specifies no rotation followed by a horizontal flip.
Rotate90FlipX   Specifies a 90-degree rotation followed by a horizontal flip.
Rotate180FlipX  Specifies a 180-degree rotation followed by a horizontal flip.
Rotate270FlipX  Specifies a 270-degree rotation followed by a horizontal flip.
RotateNoneFlipY Specifies no rotation followed by a vertical flip.
Rotate90FlipY   Specifies a 90-degree rotation followed by a vertical flip.
Rotate180FlipY  Specifies a 180-degree rotation followed by a vertical flip.
Rotate270FlipY  Specifies a 270-degree rotation followed by a vertical flip.
RotateNoneFlipXY    Specifies no rotation followed by a horizontal and vertical flip.
Rotate90FlipXY  Specifies a 90-degree rotation followed by a horizontal and vertical flip.
Rotate180FlipXY Specifies a 180-degree rotation followed by a horizontal and vertical flip.
Rotate270FlipXY Specifies a 270-degree rotation followed by a horizontal and vertical flip.

edit


something like this too?

     draw(new Bitmap (img).rotateflip(param))


ok, rotateflip doesn't return an image

looking at this, only one flip is enough from the rotateflip. no?

RotateNoneFlipNone  Specifies no rotation and no flipping.
Rotate90FlipNone    Specifies a 90-degree rotation without flipping.
Rotate180FlipNone   Specifies a 180-degree rotation without flipping.
Rotate270FlipNone   Specifies a 270-degree rotation without flipping.
RotateNoneFlipX Specifies no rotation followed by a horizontal flip.
Rotate90FlipX   Specifies a 90-degree rotation followed by a horizontal flip.
Rotate180FlipX  Specifies a 180-degree rotation followed by a horizontal flip.
Rotate270FlipX  Specifies a 270-degree rotation followed by a horizontal flip.
RotateNoneFlipY Specifies no rotation followed by a vertical flip.
Rotate90FlipY   Specifies a 90-degree rotation followed by a vertical flip.
Rotate180FlipY  Specifies a 180-degree rotation followed by a vertical flip.
Rotate270FlipY  Specifies a 270-degree rotation followed by a vertical flip.
RotateNoneFlipXY    Specifies no rotation followed by a horizontal and vertical flip.
Rotate90FlipXY  Specifies a 90-degree rotation followed by a horizontal and vertical flip.
Rotate180FlipXY Specifies a 180-degree rotation followed by a horizontal and vertical flip.
Rotate270FlipXY Specifies a 270-degree rotation followed by a horizontal and vertical flip.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文