Not*_*Dan 2 .net c# gdi+ winforms
我想在图像的C#(WinForms)中绘制一个反射,所以我需要能够水平翻转图像.我知道我可以用image.RotateFlip做到这一点,但这种方法的问题是我必须翻转图像两次,这样我才能在下一个画面右侧再次绘制它.每张图片每次涂装两次这样做似乎很慢.
我想在绘制图像时进行翻转,所以我只需翻转一次,但我找不到任何方法来做到这一点.这可能吗?
我考虑的另一种方法是以某种方式翻转图形对象,正常绘制图像,然后向后翻转图形对象,以便下一个绘图是正确的.如果这比翻转图像快两倍,是否可以这样做?
此外,我不想在内存中保留2张图像,因此我无法复制图像并翻转克隆.
从这里得到这个代码并检查,看看它是否有任何帮助.
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);
}
}
Run Code Online (Sandbox Code Playgroud)