简体   繁体   English

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

[英]How do I draw an image reflection in WinForms?

I want do draw a reflection in C# (WinForms) of an image, so I need to be able to flip the image horizontally. 我想在图像的C#(WinForms)中绘制一个反射,所以我需要能够水平翻转图像。 I know I can do this with image.RotateFlip, but the problem with this approach is that I have to flip the image twice so I can draw it again the right side up on the next paint. 我知道我可以用image.RotateFlip做到这一点,但这种方法的问题是我必须翻转图像两次才能在下一个画面上再次绘制它。 Doing this twice per paint per image seems to be slow. 每张图片每次涂装两次这样做似乎很慢。

I would like to do the flip when I draw the image so I only have to flip it once, but I can't find any way to do this. 我想在绘制图像时进行翻转,所以我只需翻转一次,但我找不到任何方法来做到这一点。 Is this possible? 这可能吗?

Another approach I've considered is somehow flipping the graphics object, drawing the image normally, and then flipping the graphics object back so that the next paint is correct. 我考虑的另一种方法是以某种方式翻转图形对象,正常绘制图像,然后向后翻转图形对象,以便下一个绘图是正确的。 If this is faster than flipping the image twice, is it possible to do? 如果这比翻转图像快两倍,是否可以这样做?

Also, I don't want to keep 2 images in memory, so I can't copy the image and flip the clone. 此外,我不想在内存中保留2张图像,因此我无法复制图像并翻转克隆。

Got this code from here and check out and see if it is of any help. 这里得到这个代码并检查,看看它是否有任何帮助。

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

edit 编辑

something like this too? 这样的事情呢?

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

ok, rotateflip doesn't return an image 好的,rotateflip不会返回图像

looking at this , only one flip is enough from the rotateflip. 看着这个 ,旋转翻转只有一次翻转就足够了。 no? 没有?

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM