gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:50:40 24 4
gpt4 key购买 nike

我想在 C# (WinForms) 中绘制图像的倒影,因此我需要能够水平翻转图像。我知道我可以用 image.RotateFlip 做到这一点,但这种方法的问题是我必须翻转图像两次,这样我才能在下一次绘制时再次将它画在右侧。每幅图像每次绘制两次似乎很慢。

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

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

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

最佳答案

here 获得此代码并查看它是否有任何帮助。

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);
}
}

关于c# - 如何在 WinForms 中绘制图像反射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2001133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com