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

时间:2010-01-04 18:09:06

标签: c# .net winforms gdi+

我想在图像的C#(WinForms)中绘制一个反射,所以我需要能够水平翻转图像。我知道我可以用image.RotateFlip做到这一点,但这种方法的问题是我必须翻转图像两次才能在下一个画面上再次绘制它。每张图片每次涂装两次这样做似乎很慢。

我想在绘制图像时进行翻转,因此我只需要翻转一次,但我找不到任何方法来执行此操作。这可能吗?

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

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

2 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:1)

修改

<击> 这样的事情呢?

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

<击> 好的,rotateflip不会返回图像

looking at this,只有一次翻转就足够了。没有?

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.