代码之家  ›  专栏  ›  技术社区  ›  NotDan

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

  •  2
  • NotDan  · 技术社区  · 15 年前

    我想在图像的C(WinForms)中绘制一个反射,因此我需要能够水平翻转图像。我知道我可以用image.rotateflip来完成这个操作,但是这种方法的问题是我必须翻转图像两次,这样我才能在下一次绘制时在右边再次绘制它。每幅图片每画两次这样做似乎很慢。

    我想做翻转时,我画的图像,所以我只需要翻转它一次,但我找不到任何方法做这件事。这有可能吗?

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

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

    2 回复  |  直到 15 年前
        1
  •  7
  •   Shoban    15 年前

    此代码来自 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
  •  1
  •   Fredou    15 年前

    编辑

    也像这样?

         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.