【问题标题】:How do I draw an image reflection in WinForms?如何在 WinForms 中绘制图像反射?
【发布时间】:2010-01-04 18:09:06
【问题描述】:

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

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

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

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

【问题讨论】:

  • 为什么不想在内存中保留两张图片?这似乎是最简单的方法。

标签: c# .net winforms gdi+


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    编辑

    也有这样的吗?

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

    好的,rotateflip 不返回图像

    looking at this,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.
    

    【讨论】:

    • 要使用反射绘制图像,我必须 (1) 将图像正面朝上绘制,然后我必须 (2) 翻转它以绘制反射,然后我必须将其翻转回来以便下一个油漆步骤 (1) 将其正面朝上。这是因为实际的 Image 实例现在被翻转了。这有意义吗?
    • 是图像还是位图?对象?
    • 这是一个 System.Drawing.Bitmap 对象。
    猜你喜欢
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2011-05-13
    相关资源
    最近更新 更多